2013-04-18 31 views
1

我在这一行上发出警告,声明actionWithTarget方法已被弃用。 任何一个能说出哪一个替代方法可以在cocos2dx使用cocos2dx中的CCCallFunc用法

CCCallFunc *callBackfunc = CCCallFunc::actionWithTarget(this, 
          callfunc_selector(GamePlay::startTrumphetAnimation)); 

感谢

+0

在函数定义中传递参数startTrumphetAnimation(CCObject * sender) –

回答

4

试试这个:

CCCallFunc *func = CCCallFunc::create(this, callfunc_selector(GameOverScene::MyFunction)); 

//声明此功能也

void GameOverScene::MyFunction(CCObject* sender) 
{ 

} 
0

,如果你正在使用新版本的Cocos2dx,

auto funcCallAction = CallFunc::create([=](){ 
    // TODO: do you stuff here 
    startTrumphetAnimation(); 
}); 

runAction(funcCallAction); 
0

试试这个

CCCallFunc *calFunc = CCCalFunc::create(this,callfunc_selector(ClassName::methodName)); 

如果您正在使用cocos2dx V3:以这种方式

无效游戏:: startTrumphetAnimation(CCObject *发件人)

CallFunc *calFunc = CalFunc::create(CC_CALLBACK_1(ClassName::methodName,this)); 


void ClassName::methodName(Ref* sender) 
{ 
} 
0

写函数定义 {

}

0

如果使用COCOS2DX-3.0或3.14v

runAction(CallFunc::create([=]() { startTrumphetAnimation() })); 

但是,你应该写的游戏类的任何方法中这条线。

+0

“(=)”的含义是什么? – OscarLeif

+0

[=]通过复制和当前对象通过引用捕获lambda主体中使用的所有自动变量(如果存在) –