Libgdx Hud with two stages

| | August 6, 2015

I have an app that’s currently working with a single stage but i need to add a side display/section as a HUD, with scores/lives etc on it, so that the HUD is on the left, and the main hand screen on the right. The main game screen will be fixed and will not move around.

From researching I’ve found a couple of solutions.

1 – two stages 2 – a group with two groups to it, possibly using a horizontalgroup 3 – two cameras one stage 4 – one stage, one camera, but changing the position of the camera for each set of actors.

I think, option 1 is my preference, but i have some questions.

Do stages always fill the whole screen, or can i start then where i want? This would make it easier for the right hand screen to calculate positions based on 0,0 of that screen rather than always having to add the width of the HUD on to any calculations.
Do i need to work about viewports? Currently I’m not using one (which i think means my stage is set to scaling by default) but nothing looks stretched as a result of this. I don’t know much about viewports, but there always seems to be a compromise to be made with them, i.e. black bars top or sides.
If I have two stages, do they each have their own camera? Do I need to with about this? Can I possibly aim the right hand camera at an offset so i can still draw things from 0,0 with that being the bottom left corner of the right stage, not the whole screen?
Finally, off topic, I am a little confused about spritebatch. I’m not currently using one, because I use a stage. Is that OK, or should i still be using one in conjunction with a stage somehow? And add all my actors to that?

One Response to “Libgdx Hud with two stages”

    • LibGDX has Viewport, which helps you do exactly what you are trying to achieve. You use the Viewport to specify where the Stage should be drawn and how big it is.

    • The Viewport does not change the local coordinate system of the Stage itself, so you don’t have to add an x offset to everything you want to include in the right hand stage (everything starts at (0, 0)).

    • And yes, each Stage has its own Camera and its own SpriteBatch.

Leave a Reply