schedule_selector problem in cocos 3.2

Hi,

I try to use schedule_selector in sceduleOnce function, but I’ve get an error:

invalid static_cast from type 'void (*)(float)' to type 'cocos2d::SEL_SCHEDULE {aka void (cocos2d::Ref::*)(float)}

Here is my code:

void SplashScene::onEnterTransitionDidFinish() {
	Layer::onEnterTransitionDidFinish();
	this->scheduleOnce(schedule_selector(SplashScene::runMenu), 2.0f);
}

void SplashScene::runMenu(float dt) {
	auto scene = MenuScene::createScene();
	Director::sharedDirector()->replaceScene(scene);
}

Your code works for me, so I’m not sure what the problem is. However, allow me to suggest an alternative:

void SplashScene::onEnterTransitionDidFinish()
{
    Layer::onEnterTransitionDidFinish();
    auto delay = DelayTime::create(2.0f);
    auto func = CallFunc::create(CC_CALLBACK_0(SplashScene::runMenu, this));
    this->runAction(Sequence::create(delay, func, NULL));
}

void SplashScene::runMenu()
{
    // stays the same
    ....
}
1 Like