【发布时间】:2017-05-13 03:25:56
【问题描述】:
我有以下代码,我想在暂停菜单中单击 moreButton 时调用一个函数。但是即使按下按钮我也无法调用该方法,可能是因为整个游戏都暂停了。我错过了什么吗?我很想听听你的意见!
auto pauseLayer=LayerColor::create(Color4B::BLACK, WINSIZE.width, WINSIZE.height);
auto pauseLabel=Label::createWithTTF("Paused", "fonts/Marker Felt.ttf", 24);
pauseLabel->setPosition(WINSIZE.width / 2.0, WINSIZE.height/ 2.0);
pauseLayer->addChild(pauseLabel);
// Add your required content to pauseLayer like pauseLabel
pauseLayer->setVisible(false);
pauseLayer->setOpacity(220); // so that gameplay is slightly visible
addChild(pauseLayer, ZOrder::Level);
auto pauseButton = MenuItemImage::create("CloseNormal.png","CloseSelected.png",[pauseLayer](Ref*sender){
if(!Director::getInstance()->isPaused()) {
Director::getInstance()->pause();
pauseLayer->setVisible(true);
auto moreButton = MenuItemImage::create("more.png","more.png","more.png",[](Ref*sender){
std::string url = "https://play.google.com/store/xxx";
cocos2d::Application::getInstance()->openURL(url);
});
moreButton->setPosition(WINSIZE.width / 2.0, WINSIZE.height/ 2.0+50);
pauseLayer->addChild(moreButton, ZOrder::Level);
pauseLayer->addChild(moreButton);
} else {
Director::getInstance()->resume();
pauseLayer->setVisible(false);
}
});
auto menu = Menu::create(pauseButton, NULL);
menu->setPosition(WINSIZE.width / 2.0, WINSIZE.height - 50);
addChild(menu, ZOrder::Level);
【问题讨论】:
标签: android c++ cocos2d-x cocos2d-x-3.0