Author Topic: 2D games with ui elements mixed in game  (Read 3338 times)

Saxi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 24
    • View Profile
2D games with ui elements mixed in game
« on: August 06, 2014, 02:30:26 AM »
What is the best practice for building a game that has no clear distinction between UI and Game outside of the menu screens. 

Do you remove the default scene camera and create a UIRoot and put everything under that?
Would you use nGUI to keep your game sprites sized for different aspect ratios?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 2D games with ui elements mixed in game
« Reply #1 on: August 07, 2014, 12:35:17 AM »
This is highly dependent on the game you're making and there is no one answer to this question. Just go with whatever works best for the type of the game you're working on. Remember, UIRoot is optional -- all you need is a UIPanel to draw the UI elements underneath it.

Saxi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 24
    • View Profile
Re: 2D games with ui elements mixed in game
« Reply #2 on: August 07, 2014, 12:04:12 PM »
This is highly dependent on the game you're making and there is no one answer to this question. Just go with whatever works best for the type of the game you're working on. Remember, UIRoot is optional -- all you need is a UIPanel to draw the UI elements underneath it.

I haven't even figured out how to do it, so I have no preference.
Should I be fighting to try to get nGUI's camera to work with the default camera, or do I just trash the default camera and build off nGUI's camera.  There are many times I won't have a distinct gui and game, like health bars, and other things.  If I am doing a 2D game should I be using two cameras or focus on one? (I know there are specific cases you need a 2nd camera for specific reasons, but just in general). 

Also should I be using nGUI to keep all the game element sprites (player, enemy and so on) sized for different aspect ratios on mobile, or is that just for the gui elements?

I know there are different ways to do it, but I am not really what works, much less what is better.  I've been playing around with it, but I can't figure out what I should be doing.  Mobile aspect ratio been kicking my ass (and not just GUI, the entire game).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 2D games with ui elements mixed in game
« Reply #3 on: August 08, 2014, 08:04:14 AM »
It depends... do you want your UI elements to mix with your game elements (appear behind game elements, etc?) If so, then you have to go with the 1 camera approach. Otherwise keeping your UI under your UI camera will be cleaner and easier to work with.

I'm not quite sure what you mean by keeping sprites sized for different aspect ratios or only the GUI elements. When the camera's orthographic size doesn't change, screen resolution changes have no effect, and sprites remain the same size proportionally. This is "Fixed Size" option on the UIRoot for NGUI. When it's "Pixel Perfect", then the screen size changes will effectively make your elements bigger or smaller proportionally to the height of the screen.

I strongly advise you to start by following NGUI's tutorials and watching the tutorial videos until you get a hang of all the basics and of how NGUI works.

Aspect ratio changes can be addressed by anchoring widgets.

Saxi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 24
    • View Profile
Re: 2D games with ui elements mixed in game
« Reply #4 on: August 09, 2014, 12:18:54 AM »
It depends... do you want your UI elements to mix with your game elements (appear behind game elements, etc?) If so, then you have to go with the 1 camera approach. Otherwise keeping your UI under your UI camera will be cleaner and easier to work with.

I'm not quite sure what you mean by keeping sprites sized for different aspect ratios or only the GUI elements. When the camera's orthographic size doesn't change, screen resolution changes have no effect, and sprites remain the same size proportionally. This is "Fixed Size" option on the UIRoot for NGUI. When it's "Pixel Perfect", then the screen size changes will effectively make your elements bigger or smaller proportionally to the height of the screen.

I strongly advise you to start by following NGUI's tutorials and watching the tutorial videos until you get a hang of all the basics and of how NGUI works.

Aspect ratio changes can be addressed by anchoring widgets.

I've gone through the new tutorials.  But I am still confused by things like having player and enemy objects that have health bars or damage text or other objects in the game scene that have nGUI elements.  This would mean they would need to be under a panel, so it seems easier that you put everything under a panel if there is mixed as it seems to be more confusing to have some things there and some things not when there isn't a strict gui/game separation.  When doing this, would you use nGUI to handle the changes in aspect ratios?  I understand about anchoring, but that's not going to help with objects like the player, and other game related things that have gui objects attached.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 2D games with ui elements mixed in game
« Reply #5 on: August 09, 2014, 05:13:29 PM »
Aspect ratio changes will let you see more or less of the game, there is no way around it. Anchors help here with your UI, but your game is up to you to do. Do you even care? So what if the player can see more to the left or right. Also note that NGUI doesn't *do* anything about aspect ratio changes. Anchoring content will make it stay in a specific place, but NGUI doesn't do anything on its own.