我是Cocos2d-x的新手。 我有一个ABCScene,在这里,我想显示一个对话框或其他东西告诉玩家他们完成了游戏关卡。它还有按钮“重播”+“下一步” 我怎么能这样做。
任何想法都会被欣赏。 谢谢你的帮助。
答案 0 :(得分: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);
}
答案 1 :(得分:-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();
}
});