我正在与 AndEngine 一起构建我的游戏...我正在创建菜单屏幕,其中至少有 4 个垂直设置的菜单项。
第 1、2 和 4 项运行良好,但是当它(在屏幕上)单击指向 id 2 的 menuItem onclick 侦听器时,第 3 项出现问题,并且动画精灵/图像也转到第 2 项。
这是我的代码
菜单项 ID
private MenuScene menuChildScene;
private final int SINGLE_GAME = 0;
private final int MULTI_GAME = SINGLE_GAME+ 1;
private final int HIGH_SCORE = MULTI_GAME + 1;
private final int ABOUT = HIGH_SCORE + 1;
创建菜单项的东西
private void createMenuChildScene()
{
menuChildScene = new MenuScene(camera);
menuChildScene.setPosition(0,0);
final IMenuItem opNewgame = new ScaleMenuItemDecorator(new SpriteMenuItem(SINGLE_GAME, resourcesManager.btnSinglegame, vbom), 1.2f, 1);
final IMenuItem opMultiGame = new ScaleMenuItemDecorator(new SpriteMenuItem(MULTI_GAME, resourcesManager.btnMultiPlayergame, vbom), 1.2f, 1);
final IMenuItem opHightScore = new ScaleMenuItemDecorator(new SpriteMenuItem(HIGH_SCORE, resourcesManager.btnhighscore, vbom), 1.2f, 1);
final IMenuItem opAbout= new ScaleMenuItemDecorator(new SpriteMenuItem(ABOUT, resourcesManager.btnabout, vbom), 1.2f, 1);
menuChildScene.addMenuItem(opNewgame);
menuChildScene.addMenuItem(opMultiGame);
menuChildScene.addMenuItem(opHightScore);
menuChildScene.addMenuItem(opAbout);
menuChildScene.buildAnimations();
menuChildScene.setBackgroundEnabled(false);
opNewgame.setPosition(opNewgame.getX(), opNewgame.getY() - 25);
opMultiGame.setPosition(opMultiGame.getX(), opNewgame.getY() - 105);
opHightScore.setPosition(opHightScore.getX(), opMultiGame.getY() - 105);
opAbout.setPosition(opAbout.getX(), opHightScore.getY() - 105);
menuChildScene.setOnMenuItemClickListener(this);
setChildScene(menuChildScene);
}
onlick 句柄和监听器..
@Override
public boolean onMenuItemClicked(
org.andengine.entity.scene.menu.MenuScene pMenuScene,
IMenuItem pMenuItem, float pMenuItemLocalX, float pMenuItemLocalY) { Log.i(TAG, HIGH_SCORE + " click : " + pMenuItem.getID());
// TODO Auto-generated method stub
switch(pMenuItem.getID()){
case SINGLE_GAME:
resourcesManager.click.play();
SceneManager.getInstance().loadGameScene(engine);
return true;
case MULTI_GAME:
resourcesManager.click.play();
return true;
case HIGH_SCORE:
resourcesManager.click.play();
return true;
case ABOUT:
resourcesManager.click.play();
return true;
default:
return false;
}
}
请帮助我必须更改一个以使我的所有菜单正常工作..
谢谢,最好的问候