【发布时间】:2017-03-28 22:31:46
【问题描述】:
我正在尝试在每个图像(playIcon,pauseIcon)上创建 eventListner,但它无法使用 touchUp 和 touchDown
这是我的代码:
TextureAtlas buttonsPlayPause = new TextureAtlas("uiii/uiii.pack");
skin.addRegions(buttonsPlayPause);
TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
textButtonStyle.font = font;
textButtonStyle.up = skin.getDrawable("pauseIcon");
textButtonStyle.checked = skin.getDrawable("playIcon");
TextButton button = new TextButton("", textButtonStyle);
button.setY(pauseY);
button.setX(Gdx.graphics.getWidth()/6);
button.setSize(150,150);
stage.addActor(button);
//pause/playAction
button.addListener(new ClickListener() {
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {resume();
}
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
pause();
return true;
}
});
现在发生的情况是按钮侦听器的行为类似于“istouched()”而不是“justtouched()”。当我点击按钮时,游戏会暂停,但每当我移开手指时,游戏不会暂停。
【问题讨论】:
-
你有没有通过这个 Gdx.input.setInputProcessor(stage); 将 stage 设置为 InputProcessor;
-
从您的评论中仍然不清楚您想要发生什么,以及它目前的行为有什么问题。
-
@Tenfour04。现在发生的是按钮侦听器的行为类似于“istouched()”而不是“justtouched()”。当我点击按钮时,游戏暂停,但每当我移开手指时,没有暂停,游戏运行
-
@AbhishekAryan 请阅读我的编辑
-
这是预期的,因为您在
touchUp方法中调用了resume()。