如果玩家想退出,我希望我的游戏不响应菜单屏幕上的后退键,所以他必须点击退出按钮退出游戏
我的class MenuScreen implements GestureListener, InputProcessor
并且stage
因为我想使用fling()
GestureListener
和keyDown()
InputProcessor
所以我这样做
multiplexer = new InputMultiplexer(stage, new GestureDetector(this), this);
Gdx.input.setInputProcessor(multiplexer);
Gdx.input.setCatchBackKey(false);
但这没有任何作用
我也尝试在keyDown()
而不是show()
@Override
public boolean keyDown(int keycode)
{
if(keycode == Input.Keys.BACK)
Gdx.input.setCatchBackKey(false);
return true;
}
但也没有发生
答案 0 :(得分:2)
如果您希望应用程序捕获后退密钥而不是操作系统,那么您希望使用true
而不是false
作为setCatchBackKey
方法的参数。 See also the documentation:
设置是否应捕获Android上的BACK按钮。这样可以防止应用暂停。对桌面没有任何影响。
答案 1 :(得分:1)
正如@Xoppa所说,当你应该使用true时,你会使用false。
此外,响应按下按钮调用此代码并不是很有意义,因为它是如何响应按钮的设置。事实上,keyDown
永远不会被调用后退按钮,因为Libdgx并没有抓住它。您应该只在create()
中调用一次。