I made a game using scene2d. Now I would like to add a HUD to my game. For that, I would like to place widgets on a table, and then add the table as a actor in a stage. My question is now: Should I create a second stage, which holds the table, or should I add the table in my existing stage. What is the correct way to add a HUD, if I already have a stage?
Asked
Active
Viewed 734 times
2
-
1Absolutely make a second Stage. It is likely you will want to use a different kind of Viewpory for UI stuff. – Tenfour04 Feb 18 '17 at 17:09
-
@Tenfour04 What do you mean different Viewport. I use a Fit ViewPort for my game. Does a different Viewport mean different dimensions or a different type of Viewport? – Stefan B Feb 18 '17 at 17:58
-
1Different type and/or dimensions. In my opinion gameplay should be using ExtendViewport for like 99% of cases. That eliminates black bars and stretching. UI in most cases should be using either an ExtendViewport with trilinear-filtered UI elements, or a ScreenViewport, with multiple asset sizes (size used picked at runtime). The first way is easier, the second results in less blurry UI. – Tenfour04 Feb 18 '17 at 18:03
-
@Tenfour04 Doesn't the ExtendViewport, like the ScreenViewport, extend the world? Couldn't this lead to unfair advantage? – Stefan B Feb 18 '17 at 18:08
-
1That can be worked around, depending on game. For example, in side-scrolling runner, make sure the camera is positioned so everyone sees the same amount of world in the direction the character is running. The extra scenery is behind the running player, so it doesn't provide advantage. Most phones are very close to 16:9 so any advantage is likely minimal anyway. – Tenfour04 Feb 18 '17 at 18:11
-
1Consider a game like NewSuper Mario Bros. Wii. On a 4:3 TV, you don't see as much of the world. It ultimately doesn't matter because you don't compete against others in this game. – Tenfour04 Feb 18 '17 at 18:13
1 Answers
0
If your game world is bigger than your screen size then you can create second stage on your screen like for side scrollable game.
Only keep in mind that stage is heavy object due to his own SpriteBatch so if it's possible to create single stage that is better choice.
otherwise you can create stage by use of this constructor
public Stage (Viewport viewport, Batch batch)
can pass viewport having size of screen for hud and first stage spritebatch as argument.

Abhishek Aryan
- 19,936
- 8
- 46
- 65
-
2Stage is not heavy at all if you pass a SpriteBatch to its constructor. – Tenfour04 Feb 18 '17 at 17:10
-
@Tenfour04 yes you are right. When we use default constructor SpriteBatch is only thing that make stage heavy. – Abhishek Aryan Feb 18 '17 at 17:41