0

我正在尝试在 LibGDX 0.9.8 版本中实现一个简单的按钮,该按钮将更改 TouchUp 事件的屏幕。但是,Eclipse 在我覆盖的 TouchUp 方法上显示了黄色下划线,表明它没有在任何地方使用。

public void resize(int width, int height) {

    //Setting up stage failsafe
    if(_stage == null){
        _stage = new Stage(width, height, true);
    }

    _stage.clear();

    Gdx.input.setInputProcessor(_stage);

    TextButtonStyle style = new TextButtonStyle();
    style.up =  _buttonSkin.getDrawable("buttonUp");
    style.down = _buttonSkin.getDrawable("buttonDown");
    style.font = _font;

    _startButton = new TextButton("START GAME" , style);
    _exitButton = new TextButton("EXIT", style);

    ///
    ///PLACING BUTTONS
    ///

    //start button
    _startButton.setWidth(Gdx.graphics.getWidth() / 3);
    _startButton.setHeight(Gdx.graphics.getHeight() / 4);

    _startButton.setX((Gdx.graphics.getWidth() / 8) * 3);
    _startButton.setY((Gdx.graphics.getHeight() / 5) * 3);

    _startButton.setTouchable(Touchable.enabled);

    _startButton.addListener(new InputListener(){

        public boolean touchUp(InputEvent event, float x, float y, int pointer, int button) {
                _game.setScreen(new World(_game));
                System.out.print("up");
                return true;
        }

    });


    //adding buttons to scene
    _stage.addActor(_startButton);
    //_stage.addActor(_exitButton);   

我在网上做了一些研究,有几篇帖子说在某些版本的 LibGDX 中没有这个事件方法,所以我确实检查了库并在那里找到了我想要的方法。

In InputListener class :/** Called when a mouse button or a finger touch goes up anywhere, but only if touchDown previously returned true for the mouse
 * button or touch. The touchUp event is always {@link Event#handle() handled}.
 * @see InputEvent */
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
}

任何人都可以看到我做错了什么?我正在使用来自 com.badlogic.gdx.scenes.scene2d.ui.TextButton 的文本按钮;

4

1 回答 1

2

libgdx javadocs看来,您正在寻找的方法是.-

public boolean touchUp(int screenX, int screenY, int pointer, int button)

无参数InputEvent event。确保删除该额外参数,将方法声明为public,并将标记添加@Override为@PT 建议。-

@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
    super.touchUp(screenX, screenY, pointer, button);
    // Do your stuff here
} 
于 2013-09-23T18:40:11.193 回答