cocos2dx3.2开发 RPG《Flighting》(十四)暂停按钮
发布时间:2020-12-14 20:03:27 所属栏目:百科 来源:网络整理
导读:一、前言 整个教程快接近尾声了。还有一个暂停功能需要添加 二、正文 首先,我们要在右上方添加一个按钮 bool FlightLayer::init(){MenuItemImage* pauseBtnItem = MenuItemImage::create("UI/pauseBtn.png","UI/pauseBtn.png",[=](Ref* pSender){Director::
|
一、前言 整个教程快接近尾声了。还有一个暂停功能需要添加 二、正文 首先,我们要在右上方添加一个按钮
bool FlightLayer::init(){
MenuItemImage* pauseBtnItem = MenuItemImage::create("UI/pauseBtn.png","UI/pauseBtn.png",[=](Ref* pSender){Director::getInstance()->pushScene(PauseScene::create());});
Menu* pauseBtn = Menu::create(pauseBtnItem,NULL);
pauseBtn->setPosition(1180,650);
this->addChild(pauseBtn,4);
return true;
}
这个按钮很简单,回到函数也直接用lumada表达式了
点击的时候会弹出PuaseScene
class PauseScene : public Scene{
public:
virtual bool init();
CREATE_FUNC(PauseScene);
private:
void continueGame(Ref* pSender,TouchEventType type);
void stopGame(Ref* pSender,TouchEventType type);
};
#include "PauseScene.h"
bool PauseScene::init(){
Widget* pNode = GUIReader::getInstance()->widgetFromJsonFile("UI/PauseUI.json");
this->addChild(pNode,0);
Button* continueBtn = (Button*)Helper::seekWidgetByName(pNode,"continueBtn");
continueBtn->addTouchEventListener(this,toucheventselector(PauseScene::continueGame));
Button* stopBtn = (Button*)Helper::seekWidgetByName(pNode,"stopBtn");
stopBtn->addTouchEventListener(this,toucheventselector(PauseScene::stopGame));
return true;
}
void PauseScene::continueGame(Ref* pSender,TouchEventType type){
if(type == TouchEventType::TOUCH_EVENT_BEGAN){
CCLOG("GAME CONTINUE");
Director::getInstance()->popScene();
}
}
void PauseScene::stopGame(Ref* pSender,TouchEventType type){
if(type == TouchEventType::TOUCH_EVENT_BEGAN){
CCLOG("GAME STOP");
Director::getInstance()->replaceScene(ChooseScene::create());
}
} 大概就这样吧。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
