我正在尝试在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中的textbutton;
答案 0 :(得分:2)
从libgdx javadocs开始,您正在寻找的方法似乎是.-
public boolean touchUp(int screenX, int screenY, int pointer, int button)
没有参数InputEvent event
。确保删除该额外参数,将方法声明为public
,然后将标记@Override
添加为@ P.T。建议.-
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
super.touchUp(screenX, screenY, pointer, button);
// Do your stuff here
}