林與AndEngine合作,建立自己的遊戲... 林創建菜單屏幕有至少4個菜單項豎置..AndEngine:Missmatch獲得項目菜單的ID上點擊收聽
貨號1,2,和4工作正常,但沒有3時,它(屏幕上)點擊menuItem onclick聽衆指向ID號2,還有動畫精靈/圖像變成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);
}
點擊數處理和listerner ..
@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;
}
}
請幫助至極一個我必須改變,使我的所有菜單正常工作..
謝謝,最好的問候
爲什麼在'onMenuItemClicked'中使用'MenuScene'的全限定名,而不是在'createMenuChildScene'中? =>檢查您的導入MenuScene,以確保它來自AndEngine或您的同名類。 –