Scene2d在桌子上添加演员

时间:2015-07-03 09:52:42

标签: java user-interface libgdx scene2d

我有一个可滚动的表格,其中包含我的菜单,按钮,标题等的所有主要功能。现在我想要一个不会滚动的“hud”,就像在facebook messenger中一样。用“朋友”和“设置”等选项卡。问题是当我尝试在桌子后面添加其他东西时,定位关闭,我尝试添加另一个舞台但是输入不起作用,我'尝试添加另一个表,但然后定位关闭(但输入工作)

当前代码:

        //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);

给出如下结果:

image

所有这一切都工作,主表滚动,HUD保持静止,当我滚动和输入工作,但定位关闭,我无法弄清楚如何解决这个问题,因此HUD位于顶部。有任何想法吗?我是以错误的方式解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

正如我在评论中提到的,您可以使用InputMultiplexer类来处理多个阶段。

InputMultiplexer内部有一个名为addProcessor()的方法,该方法接受任何实现InputProcessor的对象并允许处理您的输入。

舞台类已实现InputProcessor,请参阅 Javadocs http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/Stage.html

那么让我们说你有两个阶段

Stage stage1 = new Stage();
Stage stage2 = new Stage();

现在你所要做的就是

InputMultiplexer multiPlexer = new InputMultiplexer();
multiPlexer.addProcessor(stage1);
multiPlexer.addProcessor(stage2);

修改

仅供参考,这是我使用1阶段

的方式
public class BattleScreen extends Table {
    private BattleActionScreen battleActionScreen;
    private BattlePokemonScreen battlePokemonScreen;
}

此表的私有成员也是表。 在我的游戏中,我在舞台上添加了BattleScreen

修改 这是展示相同的图像 Battle Screen Image