I have a scrollable table that contains all the main functions of my menu, buttons, heading etc. Now I want a "hud" on top of this that does not scroll, like in facebook messenger. with tabs for "friends" and "settings" etc. The problem is when I try to add something else to the stage after the table the positioning is off, I've tried adding another Stage but then the input doesnt work, and I've tried adding another table but then the positioning is off (but the input works)
Current code:
//table.top();
table.add(heading).colspan(2);
table.getCell(heading).spaceBottom(100);
table.row();
table.add(buttonPlay).colspan(2);
table.getCell(buttonPlay).spaceBottom(100);
table.row();
table.add(buttonExit).colspan(2);
table.getCell(buttonExit).spaceBottom(1000); //large spacing to test so scrolling works fine
table.row();
table.add(buttonFriends);
table.add(buttonSettings);
hudTable.add(buttonHud);
hudTable.debug();
stage.addActor(container);
stage.addActor(hudTable);
Gives a result that looks like this:
All this works, the main table scrolls, the HUD stays still while I scroll and the input works, but the positioning is off and I can't figure out how to fix this so the HUD is on top. Any ideas? Am I going about this the wrong way?
As I mentioned in comments you can use InputMultiplexer
class to process multiple stages.
Inside InputMultiplexer
there is a method called addProcessor()
which takes any object which implements InputProcessor
and allow your inputs to be processed.
The stage class already implements InputProcessor
see Javadocs http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/Stage.html
So let us say you have two stages
Stage stage1 = new Stage();
Stage stage2 = new Stage();
Now all you have to do is
InputMultiplexer multiPlexer = new InputMultiplexer();
multiPlexer.addProcessor(stage1);
multiPlexer.addProcessor(stage2);
EDIT
Just for reference this is how I do it using 1 stage
public class BattleScreen extends Table {
private BattleActionScreen battleActionScreen;
private BattlePokemonScreen battlePokemonScreen;
}
Both the private members of this table are also tables.
In my game I add BattleScreen
inside the stage.
EDIT Here is the image to demonstrate the same