我剛開始學習Cocos2dx,並使用基本的HelloWorld項目。我添加了一個SecondScene和一個按鈕來改變場景。但是一旦執行popScene方法,屏幕變黑,並且不會彈出到第一個場景。我不知道什麼是錯的。 下面是我修改一點點在HelloWorld.cpp代碼:popScene後得到黑屏
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
CCDirector::sharedDirector()->pushScene(SecondScence::scene());
#endif
守則SecondScene:
#include "SecondScence.h"
USING_NS_CC;
CCScene* SecondScence::scene(){
CCScene* scene=CCScene::create();
SecondScence* layer = SecondScence::create();
scene->addChild(layer);
return scene;
bool SecondScence::init(){
CCLabelTTF* label = CCLabelTTF::create("hfiejfeiojfoej", "Arial", 30);
label->setPosition(ccp(200,200));
this->addChild(label);
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"CloseNormal.png","CloseSelected.png",this,menu_selector(SecondScence::popScene));
pCloseItem->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width-20, 20));
CCMenu *pMenu = CCMenu::create(pCloseItem,NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu,1);
return true;
}
void SecondScence::popScene(CCObject* pSender){
CCDirector::sharedDirector()->popScene();
}
順便說一句,我用cocos2dx 2.2和xcode5,在控制檯打印一個消息:cocos2d的:cocos2d:釋放CCDirector 0x6906f0
場景意味着你推入堆棧的場景。(pushScene()) –