按下按钮后切换屏幕?使用LibGDX

时间:2016-12-18 22:06:03

标签: java libgdx

目前正在为学校开展游戏,我遇到了一个问题。我使用按钮(Play,Level Picker和Settings)为我的游戏创建了一个主菜单。我要做的是当按下“播放”时它将切换到用户将播放的不同屏幕。菜单名为MainMenu,我希望它切换到的屏幕名为StartGameScreen。我试过在线寻找我的答案,但似乎无法找到一些有用的东西。如果它有帮助这里是我的播放按钮的代码。任何帮助都会很棒!

    TextButton playButton = new TextButton("Play", (com.badlogic.gdx.scenes.scene2d.ui.Skin) skin); // Use the initialized skin
    playButton.setPosition(Gdx.graphics.getWidth() / 2 - Gdx.graphics.getWidth() / 8, Gdx.graphics.getHeight() / 2 + (playButton.getHeight() + buttonOffSet));
    playButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            System.out.println("play game button clicked");
        }
    });
    stage.addActor(playButton);

1 个答案:

答案 0 :(得分:2)

您应该使用 <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:textColor="#000" android:textSize="15sp" android:text="dvvdv"/> 类的setScreen方法来更改屏幕。

Game
相关问题