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?


1 Answer 1

  • 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.

  • \$\begingroup\$ That sounds like i should have one viewport per stage, and that the stage is IN the viewport? If it's the other way around like i previously thought, which viewport type should i use to avoid black bars? Or is this unavoidable? Currently i an just adding my actors to my stage and running stage.act() and stage.draw() in render. What is the spritebatch for? Thanks for the answer, it's definitely starting to make sense \$\endgroup\$ Feb 10, 2015 at 15:58
  • \$\begingroup\$ I'm sorry, but I've spent the best part of a couple of hours looking at your suggestions with not results. Mainly I can't find anyway of setting two stages to cover two different parts of the screen. I'm starting to think that a stage may not reflect part of my phones screen, but that is what a viewport does. A stage is merely an object that holds actors and a viewport together in the same place? Is that right? But basically how do I create two stages, to have diff start positions on my phones screen? Thanks \$\endgroup\$ Feb 11, 2015 at 0:41
  • \$\begingroup\$ After asking on SO as well, I got this answer, which helped. stackoverflow.com/questions/28431423/libgdx-hud-with-two-stages basically, I extended Viewport to create my own viewport, from within I could set the bounds of the viewport to fit my screen where I wanted it to. \$\endgroup\$ Feb 12, 2015 at 1:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .