0

我是 Cocos2d-x 的新手。我有一个 ABCScene,在此,我想显示一个对话框或其他内容来告诉玩家他们完成了游戏关卡。它还有按钮“重播”+“下一步”我该怎么做。

任何想法将不胜感激。感谢你的帮助。

4

2 回答 2

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);
}
于 2013-07-19T09:31:25.520 回答
-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();
        }
    });
于 2013-08-04T13:42:32.370 回答