I ran into a problem when implementing the transition page effect. First, I inherite the “HelloWorldScene” from CCLayerColor. The code is follow:
class HelloWorldScene : public cocos2d::CCLayerColor
{
public:
virtual bool init();
static cocos2d::CCScene* scene();
virtual void menuCloseCallback(CCObject* pSender);
virtual void NewGameCallback(CCObject *pSender);
CREATE_FUNC(HelloWorldScene);
};
bool HelloWorldScene::init()
{
bool bRet = false;
do
{
//////////////////////////////////////////////////////////////////////////
// super init first
//////////////////////////////////////////////////////////////////////////
CC_BREAK_IF(! CCLayerColor::initWithColor( ccc4(255,255,255,255) ));
CC_BREAK_IF(! CCLayer::init());
//////////////////////////////////////////////////////////////////////////
// add your codes below...
//////////////////////////////////////////////////////////////////////////
Next, the transition page effect. To make a demo, I just want to transtion to the same scene. So, the code is follow.
void HelloWorldScene::NewGameCallback(CCObject *pSender)
{
CocosDenshion::SimpleAudioEngine::sharedEngine()->end();
CCScene *s = new TransitionHelloWorldPage(); // empty class
CCLayer* pLayer = new HelloWorldScene();
s->addChild(pLayer);
CCScene* pScene = FlipXLeftOver::transitionWithDuration(3,s);
s->release();
pLayer->release();
if (pScene) {
CCDirector::sharedDirector()->replaceScene(pScene);
}
}
What’s wrong is that when the “NewGameCallback” is called, the transition page effect is not totally completed. Instead, it halts in the half way, and the VS pops the debug info.
Thus, I try to add a new constructor in “HelloWorldScene”.
HelloWorldScene::HelloWorldScene() {
CCLayerColor::initWithColor( ccc4(255,255,255,255) );
init();
}
Now, it works well for me, but new problem occurs. That label menu I use in this scene shows overlaps. But here, I guess the all the sprite and label loads twice? (One in constructor, one in init()).
Besides, if I delete init() in constructor, it works well. The label will not overlaps and the transition can complete. But one thing is that after the transition, the screen turns to white.
My purpose is to transition to the same page. So, after transition, the sprite and label should show again.
Someone know how to fix the problem without implementingconstructor? or how to set the background color without inheriting from CCLayerColor?
I upload my code, hoping someone could take a look.
CCOS2.0.2 InitWithColor.jpg (35.0 KB)
CCOS2.0.2 MenuItemLabel Overlaps.jpg (13.8 KB)
HelloWorldScene.cpp.zip (3.2 KB)