Cocos2d x Sel_CallFuncN无法将void强制转换为Sel_CallFuncN
我想在游戏中加入一个介绍画面。几秒钟后,它应该会变成游戏本身 在introscreen类的Init中,我尝试创建一个序列,但得到以下错误: 无法从类型void强制转换为成员指针类型 'cocos2d::SEL_CallFuncN'(又名 'void(cocos2d::CCObject::*)(cocos2d::CCNode*)' 这是我的密码:Cocos2d x Sel_CallFuncN无法将void强制转换为Sel_CallFuncN,cocos2d-x,splash-screen,Cocos2d X,Splash Screen,我想在游戏中加入一个介绍画面。几秒钟后,它应该会变成游戏本身 在introscreen类的Init中,我尝试创建一个序列,但得到以下错误: 无法从类型void强制转换为成员指针类型 'cocos2d::SEL_CallFuncN'(又名 'void(cocos2d::CCObject::*)(cocos2d::CCNode*)' 这是我的密码: bool IntroScreen::init() { if (!CCLayer::init()) { return false
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;
}
我做错了什么?在SEL\u CallFuncN中,应该将指针指向函数,而不是函数
void IntroScreen::replace(CCObject* sender){
cocos2d::CCDirector::sharedDirector()->replaceScene(Controller::scene();
}
比如说
cocos2d::SEL_CallFuncN(IntroScreen::replace)
在替换放置要调用的代码时,如果使用CallFuncN,则方法的第一个参数应该是运行函数的object
void IntroScreen::replace(CCObject* sender){
cocos2d::CCDirector::sharedDirector()->replaceScene(Controller::scene();
}
您可以在此处使用
scheduler
,而不是像这样使用CCFiniteTimeAction
this->scheduleOnce(schedule_selector(IntroScreen::replace), 3);
void IntroScreen::replace(CCObject* sender){
cocos2d::CCDirector::sharedDirector()->replaceScene(Controller::scene();
}
在顶部插入一条语句“使用命名空间cocos2d;
”,以避免在任何地方写入cocos2d::