1,GamePauseUtils.h
// // GamePauseUtils.h // AdventureKing // // Created by jianan on 15/5/12. // // #ifndef __AdventureKing__GamePauseUtils__ #define __AdventureKing__GamePauseUtils__ #include "cocos2d.h" USING_NS_CC; //操作类型 typedef enum OPERATE_TYPE{ OPERATE_TYPE_PAUSE,OPERATE_TYPE_RESUME }OPERATE_TYPE; // class GamePauseUtils { public: GamePauseUtils(); ~GamePauseUtils(); static GamePauseUtils* getInstance(); void operateAllSchedulerAndActions(Node* node,OPERATE_TYPE type,int ignoreTag); //忽略检测的tag }; #endif /* defined(__AdventureKing__GamePauseUtils__) */
2,GamePauseUtils.cpp
// // GamePauseUtils.cpp // AdventureKing // // Created by jianan on 15/5/12. // // #include "GamePauseUtils.h" static GamePauseUtils* instance = NULL; GamePauseUtils::GamePauseUtils(){ } GamePauseUtils::~GamePauseUtils(){ } GamePauseUtils* GamePauseUtils::getInstance(){ if(instance == NULL){ instance = new GamePauseUtils(); } return instance; } void GamePauseUtils::operateAllSchedulerAndActions(Node* node,int ignoreTag){ if(node->isRunning()){ switch(type){ case OPERATE_TYPE_PAUSE: node->pause(); break; case OPERATE_TYPE_RESUME: node->resume(); break; } Vector<Node*> array = node->getChildren(); if(array.size() > 0){ for(Vector<Node*>::iterator iter = array.begin(); iter != array.end();){ Node* child = *iter; if(child->getTag() == ignoreTag){ iter++; }else{ iter++; this->operateAllSchedulerAndActions(child,type,ignoreTag); } } } } }3,暂停
GamePauseUtils::getInstance()->operateAllSchedulerAndActions(rootLayer,OPERATE_TYPE_PAUSE,IGNORE_TAG);4,恢复
GamePauseUtils::getInstance()->operateAllSchedulerAndActions(rootLayer,OPERATE_TYPE_RESUME,IGNORE_TAG);原文链接:https://www.f2er.com/cocos2dx/343041.html