Libgdx文本按钮单击“侦听器未触发”

时间:2016-04-13 15:16:25

标签: java android libgdx desktop

我已经用这种方式编码了,但点击监听器仍未触发 我建立场景的方法

protected void buildStage(){
    skin = new Skin(Gdx.files.internal("ui/uiskin.json"));
    screenBg = new Image(Assets.fetchTextureRegion(21));
    title = new Image(Assets.getLogo());
    title.setHeight(64);
    title.setWidth(64);
    helpTip = new Label("Just tap",skin);
    helpTip.setColor(Color.WHITE);
    helpTip.setHeight(20);
    table = new Table().debug();
    playButton = new TextButton("Play",skin);
    table.add(playButton).padBottom(10);
    table.row();
    optionsButton = new TextButton("Options",skin);
    table.add(playButton).padBottom(10);
    table.row();
    table.add(new TextButton("WhatEver",skin)).padBottom(10);
    table.row();
    exitButton = new TextButton("Exit",skin);
    table.add(exitButton);
    table.setPosition(400,-200);
    options = new Table().debug();
    soundTitle = new Label("Sound Opions",skin);
    soundTitle.setColor(Color.NAVY);
    options.add(soundTitle).padBottom(25).colspan(2);
    options.row();

    muteCheckBox = new CheckBox("Mute All",skin);
    options.add(muteCheckBox).padBottom(10).colspan(2);
    options.row();
    options.add(new Label("Volume",skin)).padBottom(10).padRight(10);
    volumeSlider = new Slider(0, 2, 0.2f, false, skin);
    options.add(volumeSlider).padTop(10).padBottom(20);
    options.row();
    backButton=new TextButton("BACK", skin);
    options.add(backButton).colspan(2).padTop(20);
    options.setPosition(400, -200);
    muteCheckBox.setChecked(!game.soundEnabled);
    volumeSlider.setValue(game.soundVolume);
    stage.addActor(screenBg);
    stage.addActor(title);
    stage.addActor(helpTip);
    stage.addActor(table);
    stage.addActor(options);
    /**
     * Actions
     */
    playButton.addListener(new ClickListener(){
        @Override
        public void clicked(InputEvent event,float x,float y){
            Gdx.app.log("Promise","Playing");
            game.setScreen(new PromiseScreen(game));
        }
    });






    optionsButton.addListener(new ClickListener(){
        @Override
        public void clicked(InputEvent event,float x,float y){
            showMenu(false);
        }
    });


    exitButton.addListener(new ClickListener(){
        @Override
        public void clicked(InputEvent event,float x,float y){
            Gdx.app.exit();
        }
    });


    volumeSlider.addListener(new ChangeListener(){
        public void changed (ChangeEvent event, Actor actor) {
            game.soundVolume=volumeSlider.getValue();
        }
    });

    muteCheckBox.addListener(new ChangeListener() {
        public void changed (ChangeEvent event, Actor actor) {
            game.soundEnabled=!muteCheckBox.isChecked();
        }
    });

    backButton.addListener(new ClickListener(){
        @Override
        public void clicked(InputEvent event, float x, float y) {
            showMenu(true);
        }
    });

}

并在show

打电话
 @Override
public void show() {
    stage = new Stage(viewport);
    Gdx.input.setInputProcessor(stage);
    buildStage();
    title.setPosition(400-title.getWidth()/2, 450);
    helpTip.setPosition(400-helpTip.getWidth()/2, 30);
    MoveToAction actionMove = Actions.action(MoveToAction.class);
    actionMove.setPosition(400-title.getWidth()/2, 320);
    actionMove.setDuration(2);
    actionMove.setInterpolation(Interpolation.elasticOut);
    title.addAction(actionMove);
    showMenu(true);
}

任何想法为什么不起作用,我使用的是1.9.2 最好的问候

0 个答案:

没有答案