2013-07-19 41 views
0

我是Cocos2d-x中的新手。 我有一個ABCScene,在這個,我想顯示一個對話框或其他的告訴玩家他們完成了遊戲level.It也有按鈕「重播」+「下一個」 我該怎麼做。Cocos2d-x:在場景中創建對話框

任何想法將不勝感激。 感謝您的幫助。

+0

檢查這個問題http://stackoverflow.com/questions/7599285/cocos2d-how-to-create-a-popup-modal-dialog- with-cclayer – asloob

回答

2

您可以使用CCMenu。

你可以試試這個代碼:

{ 
CCSprite *gameOverBg = CCSprite::create("ui/scoreBoard.png"); 
gameOverBg->setPosition(ccp(winsize.width/2,winsize.height/2)); 
gameOverBg->setTag(1000); 
this->addChild(gameOverBg); 

CCSprite *menuItemBtn = CCSprite::create("ui/yesBtn1.png"); 
CCSprite *menuItemHvr = menuItemHvr->spriteWithFile("ui/yesBtn2.png"); 
CCMenuItemSprite *menuItem = CCMenuItemSprite::create(menuItemBtn, menuItemHvr, this, menu_selector(UIManager::menuCallbacks)); 
menuItem->setTag(1); 
menuItem->setPosition(ccp(gameOverBg->getContentSize().width/2,gameOverBg->getContentSize().height/2-100)); 

CCLabelTTF *player = CCLabelTTF::create("User Player","Thonburi", 20); 
player->setPosition(ccp(gameOverBg->getContentSize().width/2 - 100,gameOverBg->getContentSize().height/2+200)); 
player->setTag(2); 
gameOverBg->addChild(player); 

CCLabelTTF *ai = CCLabelTTF::create("AI Player", "Thonburi", 20); 
ai->setPosition(ccp(gameOverBg->getContentSize().width/2 + 100,gameOverBg->getContentSize().height/2+200)); 
ai->setTag(3); 
gameOverBg->addChild(ai); 


CCLabelTTF *user = CCLabelTTF::create("000","Thonburi", 64); 
user->setPosition(ccp(gameOverBg->getContentSize().width/2 - 100,gameOverBg->getContentSize().height/2+100)); 
user->setTag(2); 
gameOverBg->addChild(user); 

CCLabelTTF *opponent = CCLabelTTF::create("000", "Thonburi", 64); 
opponent->setPosition(ccp(gameOverBg->getContentSize().width/2 + 100,gameOverBg->getContentSize().height/2+100)); 
opponent->setTag(3); 
gameOverBg->addChild(opponent); 
CCMenu *menuGameOver = CCMenu::create(menuItem,player,ai,user,opponent,NULL); 
menuGameOver->setPosition(ccp(gameOverBg->getContentSize().width/2,gameOverBg->getContentSize().height * 0.35)); 
//menuGameOver->alignItemsHorizontallyWithPadding(8); 
menuGameOver->setPosition(CCPointZero); 
gameOverBg->addChild(menuGameOver); 
} 
+0

我試過了,但是在這一行出錯: CCMenu * menuGameOver = CCMenu :: create(menuItem,player,ai,user,opponent,NULL); 錯誤具有財產以後這樣的: dynamic_cast的(孩子)= 0 – Tom

+0

我已經嘗試沒有menuGameOver,它在屏幕上顯示,但按鈕不起作用 – Tom

-1
CCDirector.sharedDirector().getActivity().runOnUiThread(new Runnable() { 
     public void run() { 
      AlertDialog.Builder builder = new AlertDialog.Builder(CCDirector.sharedDirector().getActivity()); 
      builder.setMessage("Your Message here") 
        .setCancelable(false) 
        .setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) { 
          //your Code here 
         } 
        }) 
        .setNegativeButton("No", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) { 
          dialog.cancel(); 
         } 
        }); 
      AlertDialog alert = builder.create(); 
      alert.show(); 
     } 
    }); 
+0

值得關注,但已經嚴重過時,'導演::的getInstance() - >! '沒有'getActivity()'方法,'CCDirector'也沒有 – John