Search code examples
cocos2d-xsplash-screen

Sel_CallFuncN cannot cast void to Sel_CallFuncN


I'm trying to get an intro screen in my game. After a few seconds it should change to the game itself.

In the Init of my introscreen class, I try to make a sequence, but I'm getting the following error:

cannot cast from type void to member pointer type 'cocos2d::SEL_CallFuncN' (aka 'void(cocos2d::CCObject::*)(cocos2d::CCNode *)'

here's my code:

 bool IntroScreen::init() {
    if (!CCLayer::init()) {
        return false;
    }

    cocos2d::CCSize screenSize = cocos2d::CCDirector::sharedDirector()->getWinSize();

    cocos2d::CCSprite* logomarca = cocos2d::CCSprite::create("rayman_intro.png");
    logomarca->setPosition(ccp(screenSize.width / 2, screenSize.height / 2));
    this->addChild(logomarca, 1);

    cocos2d::CCFiniteTimeAction *seq1 = cocos2d::CCSequence::create(cocos2d::CCDelayTime::create(3.0),
                                                  cocos2d::CCCallFuncN::create(this,
                                                                               cocos2d::SEL_CallFuncN(cocos2d::CCDirector::sharedDirector()->replaceScene(Controller::scene())), NULL);

    this->runAction(seq1);

    return true;
}

What am I doing wrong?


Solution

  • You can use scheduler here instead of CCFiniteTimeAction like this..

        this->scheduleOnce(schedule_selector(IntroScreen::replace), 3);
    
    
    void IntroScreen::replace(CCObject* sender){
        cocos2d::CCDirector::sharedDirector()->replaceScene(Controller::scene();
    }
    

    Also insert a statement "using namespace cocos2d;" at the top to avoid writing cocos2d:: everywhere.