Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java LIBGDX在主菜单上有多个按钮_Java_Android_Desktop_Libgdx_2d Games - Fatal编程技术网

Java LIBGDX在主菜单上有多个按钮

Java LIBGDX在主菜单上有多个按钮,java,android,desktop,libgdx,2d-games,Java,Android,Desktop,Libgdx,2d Games,我有5个按钮,我想把主菜单上,但当我有所有的5名演员,它不工作,当我把他们都拿出来,留下一个在它的工作 你如何避免使用多个按钮 这是我的密码 public class MainMenu implements Screen { CrazyZombies game; Stage stage; TextureAtlas atlas; Skin skin; SpriteBatch batch; Button play, option, quit, custom, store, menu; publi

我有5个按钮,我想把主菜单上,但当我有所有的5名演员,它不工作,当我把他们都拿出来,留下一个在它的工作

你如何避免使用多个按钮

这是我的密码

public class MainMenu implements Screen {

CrazyZombies game;
Stage stage;
TextureAtlas atlas;
Skin skin;
SpriteBatch batch;
Button play, option, quit, custom, store, menu;

public MainMenu(CrazyZombies game) {
    this.game = game;
}

@Override
public void render(float delta) {
    Gdx.gl.glClearColor(0.09f, 0.28f, 0.2f, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    stage.act(delta);
    stage.draw();

    batch.begin();
    batch.end();
}

@Override
public void resize(int width, int height) {
    if (stage == null)
        stage = new Stage(width, height, true);
    stage.clear();

    Gdx.input.setInputProcessor(stage);


    /**
     * quit Button
     */

    TextButtonStyle styleQuit = new TextButtonStyle();
    styleQuit.up = skin.getDrawable("8layer");
    styleQuit.down = skin.getDrawable("8layer");

    quit = new Button(styleQuit);
    quit.setWidth(854);
    quit.setHeight(480);

    quit.addListener(new InputListener() {
        public boolean touchDown(InputEvent event, float x, float y,
                int pointer, int button) {
            return true;
        }

        public void touchUp(InputEvent event, float x, float y,
                int pointer, int button) {

        }
    });

    /**
     * End quit Button
     */

     /**
      * store Button
      */

    TextButtonStyle styleStore = new TextButtonStyle();
    styleStore.up = skin.getDrawable("9layer");
    styleStore.down = skin.getDrawable("9layer");

    store = new Button(styleStore);
    store.setWidth(854);
    store.setHeight(480);

    store.addListener(new InputListener() {
        public boolean touchDown(InputEvent event, float x, float y,
                int pointer, int button) {
            return true;
        }

        public void touchUp(InputEvent event, float x, float y,
                int pointer, int button) {
            game.setScreen(new StoreScreen(game));
        }
    });

    /**
     * End store Button
     */

     /**
      * customs Button
      */

    TextButtonStyle styleCustom = new TextButtonStyle();
    styleCustom.up = skin.getDrawable("10layer");
    styleCustom.down = skin.getDrawable("10layer");

    custom = new Button(styleCustom);
    custom.setWidth(854);
    custom.setHeight(480);

    custom.addListener(new InputListener() {
        public boolean touchDown(InputEvent event, float x, float y,
                int pointer, int button) {
            return true;
        }

        public void touchUp(InputEvent event, float x, float y,
                int pointer, int button) {
            game.setScreen(new CustomScreen(game));
        }
    });

    /**
     * End customs Button
     */

     /**
      * Options Button
      */

    TextButtonStyle styleOptions = new TextButtonStyle();
    styleOptions.up = skin.getDrawable("11layer");
    styleOptions.down = skin.getDrawable("11layer");

    option = new Button(styleOptions);
    option.setWidth(854);
    option.setHeight(480);

    option.addListener(new InputListener() {
        public boolean touchDown(InputEvent event, float x, float y,
                int pointer, int button) {
            return true;
        }

        public void touchUp(InputEvent event, float x, float y,
                int pointer, int button) {
            game.setScreen(new OptionScreen(game));
        }
    });

    /**
     * End Options Button
     */

     /**
      * Play Button
      */

    TextButtonStyle stylePlay = new TextButtonStyle();
    stylePlay.up = skin.getDrawable("7layer");
    stylePlay.down = skin.getDrawable("7layer");

    play = new Button(stylePlay);
    play.setWidth(854);
    play.setHeight(480);

    play.addListener(new InputListener(){

    });

    play.addListener(new InputListener() {
        public boolean touchDown(InputEvent event, float x, float y,
                int pointer, int button) {
            return true;
        }

        public void touchUp(InputEvent event, float x, float y,
                int pointer, int button) {
            Gdx.app.log(CrazyZombies.LOG, "un-touched");
            game.setScreen(new GameScreen(game));
        }
    });

    /**
     * End Play Button
     */

    /**
     * start Background
     */

    TextButtonStyle styleMenu = new TextButtonStyle();
    styleMenu.up = skin.getDrawable("background");

    menu = new Button(styleMenu);
    menu.setWidth(854);
    menu.setHeight(480);

    /**
     * End Background
     */

    //stage.addActor(menu);
    stage.addActor(play);
    //stage.addActor(option);
    //stage.addActor(store);
    //stage.addActor(custom);
    //stage.addActor(quit);

}

@Override
public void show() {
    Audio.playMusic(true);
    batch = new SpriteBatch();
    atlas = new TextureAtlas("data/mainmenu/mainmenu.pack");
    skin = new Skin();
    skin.addRegions(atlas);
}

@Override
public void hide() {
    dispose();
}

@Override
public void pause() {

}

@Override
public void resume() {

}

@Override
public void dispose() {
    batch.dispose();
    skin.dispose();
    atlas.dispose();
    stage.dispose();
    Audio.dispose();
}
}

  • 创建一个表对象
  • 将所有按钮添加到其中
  • 将该表对象添加到阶段
  • 希望能有帮助。祝你好运。

    问题已经问过了。