0
我刚开始用andEngine开发游戏,现在遇到了Android设备中的硬件菜单按钮问题。我想要做的就是调用一个方法“showMenu()
”来显示一个自定义的菜单场景,我用下面的代码做了。但是,无论何时点击硬件菜单按钮,应用程序列表都会显示出来,而不是方法。我如何设法通过菜单按钮调用方法?我很想听到你的消息!单击硬件菜单按钮时无法调用方法
@Override
public boolean dispatchKeyEvent(KeyEvent e) {
if (e.getAction() == KeyEvent.ACTION_DOWN && e.getKeyCode() == KeyEvent.KEYCODE_BACK) {
//if paused
if (isPaused) {
//use thread when tring to use detachself and detachChildren
getBaseActivity().runOnUpdateThread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < pauseBg.getChildCount(); i++) {
unregisterTouchArea((ButtonSprite) pauseBg.getChildByIndex(i));
}
pauseBg.detachChildren();
pauseBg.detachSelf();
}
});
isPaused = false;
isTouchEnabled = true;
return true;
} else {
return false;
}
} else if (e.getAction() == KeyEvent.ACTION_DOWN && e.getKeyCode() == KeyEvent.KEYCODE_MENU) {
//if not paused show menu
if (!isPaused) {
showMenu();
}
return true;
}
return false;
}