I have sprite with a Move action, I want to call a function with 3 parameters when sprite finish Move action, I try to use CC_CALLBACK_3
and CallFuncN
but i don't know where I put my parameters.

- 4,177
- 11
- 45
- 65

- 9
- 1
- 5
-
post some code to better understand your situation – musikov Dec 28 '14 at 20:46
1 Answers
You shouldn't use CC_CALLBACK_3, use CC_CALLBACK_1 instead:
void callfunc1(Node* pSender, int i, int j, int k);
sprite->runAction(CallFuncN::create(CC_CALLBACK_1(HelloWorld::callfunc1, this,1,2,3)));
When you take a look at the create funtion of CallFuncN:
static CallFuncN * create(const std::function<void(Node*)>& func);
It receives a std::function with only one parameter.
So you should use CC_CALLBACK_1 to rebind the function with 3 or more parameters to a method accept only one parameter and the only one parameter must be Node* and its subtype.
In the CallFuncN example, the cocos2d-x engine would pass the sprite as the first argument to the callfunc1 method. So you only need to care about passing the remaining argument.
BTW, you don't have to use the CallFuncN and the CallFuncN class restrict you to define a method whose first argument must be Node* and its subtype, you could also use CallFunc, here is the code snippet:
void callfunc2(Node* pSender, int i, int j);
sprite->runAction(CallFunc::create(CC_CALLBACK_0(HelloWorld::callfunc2, this,sprite,1,2)));
This time, we pass the "sprite" as the first argument to the "callfunc2" method.

- 489
- 4
- 8