我做在cocos2dx一場比賽,所以我做了一個名爲類CoCoGui
和我也做了IntroPage
類,從CCLayerColor
繼承的介紹遊戲頁面以及從CCLayerColor
繼承的StartPage
類。 我要顯示的介紹頁面爲第2秒鐘,然後顯示StartingPage
但在CoCoGui
的updateGame
功能(這是遊戲的主循環)中,當調用replaceScene
方法和Scene
成爲更換, updateGame
方法將不會再被調用! 請幫我解決這個問題 謝謝!更換場景之後,Schedule方法不工作了
這裏的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;
}
嘗試理解cocos2d在開始編程之前如何通過CCDirector處理CCScene,CCLayer和節點。確保您知道何時啓動場景,在進入場景之前調用了哪些默認功能,以及在離開場景後調用了哪些功能。有2本書非常好:Cocos2d for iPhone遊戲開發手冊/學習iOS 5的cocos2d遊戲開發。cocos2d-x使用與cocos2d相同的方式 –