我正在 cocos2dx 中制作游戏,所以我制作了一个名为的类,CoCoGui
并且我还制作了一个IntroPage
继承自CCLayerColor
游戏介绍页面的StartPage
类和一个继承自的类CCLayerColor
。我想在前2秒显示介绍页面,然后在(这是游戏的主循环)的函数中显示StartingPage
但是,当方法被调用并且被替换时,该方法将不再被调用!请帮我解决这个问题谢谢!updateGame
CoCoGui
replaceScene
Scene
updateGame
这是 CoCoGui.h 文件:
StartingPage
并且IntroPage
是两个继承自的类CCLayerColor
#ifndef _COCOGUI_H_
#define _COCOGUI_H_
#include "StartingPage.h"
#include "..\Classes\WorkSpace.h"
#include "..\Classes\GameBoard.h"
#include "..\Classes\IntroPage.h"
using namespace cocos2d;
class CoCoGui : public CCLayerColor{
public:
CoCoGui();
void addScene (CCScene * startPage, CCScene * work);
virtual ~CoCoGui(void);
void updateGame ( float dt );
virtual bool init();
static CCScene* scene();
CREATE_FUNC(CoCoGui);
private:
bool isInit;
CCScene * runnigScene;
IntroPage * introPage;
StartingPage * startingPage;
void onEnterTransitionDidFinish();
void menuCloseCallback(CCObject* pSender);
public:
CCScene * getRunningScene(void);
};
#endif /* COCOGUI_H */
这里也是 CoCoGui.cpp 文件
#include "CoCoGui.h"
#include <iostream>
using namespace std;
CCScene* CoCoGui::scene(){
CCScene *scene = CCScene::create();
CoCoGui *layer = CoCoGui::create();
scene->addChild(layer);
return scene;
}
CoCoGui::CoCoGui ( )
{
this->isInit = false;
this->introPage = new IntroPage ( );
this->startingPage = new StartingPage ( );
}
CoCoGui::~CoCoGui(void)
{
delete introPage;
delete startingPage;
}
void CoCoGui::menuCloseCallback(CCObject* pSender)
{
CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
}
bool CoCoGui::init ( ){
if ( !CCLayerColor::initWithColor ( ccc4 (100,100,100,255) ) ){
return false;
}
this->schedule ( schedule_selector ( CoCoGui::updateGame ), 0.5 );
return true;
}
void CoCoGui::updateGame ( float dt ){
cout << "Update Called" << endl;
if ( !isInit )
return;
CCScene * scene = NULL;
if ( !this->introPage->isIntroPageDone ( ) ){
scene = IntroPage::scene();
}
else if ( this->introPage->isIntroPageDone ( ) ){
scene = StartingPage::scene();
}
CCDirector::sharedDirector()->replaceScene(scene);
}
void CoCoGui::onEnterTransitionDidFinish ( ){
isInit = true;
}
CCScene * CoCoGui::getRunningScene(void)
{
return this->runnigScene;
}