[Solved]Action CallBack

Hey i am trying to get the callback of a action .First one is working fine without parameter.
void EnemyRotatingAnimationCallback();
CCCallFunc::create(CC_CALLBACK_0(GamePlay::EnemyRotatingAnimationCallback,this))

But now i want to pass an integer with the callbackfunction function as a parameter.How can i do this?
Error:-
void EnemyRotatingAnimationCallback(int i);
CCCallFunc::create(CC_CALLBACK_0(GamePlay::EnemyRotatingAnimationCallback(5),this))

pls suggest me some code.

Try with this code.
CCCallFunc::create(CC_CALLBACK_0(GamePlay::EnemyRotatingAnimationCallback,this,5))

its working…thanks
but its giving error when i am writing CC_CALLBACK_1 instead of CC_CALLBACK_0.any idea?

Difference between below 2 is that 1st code is passing “function” but 2nd is passing “function call”.

CCCallFunc::create(CC_CALLBACK_0(GamePlay::EnemyRotatingAnimationCallback,this))
CCCallFunc::create(CC_CALLBACK_0(GamePlay::EnemyRotatingAnimationCallback(5),this))

CC_CALLBACK_0 is MACRO which expects a callback fn along with infinite arguments. But these arguments shouldn’t be having any placeholder(C++ std:bind accept placeholders). CC_CALLBACK_1 is MACRO which accepts callback function along with infinite arguments but with 1 placeholder… Nothing to do with how many arguments your callback function accepts(which is EnemyRotatingAnimationCallback in your case, can u plz shorten the name to atleastEnemyRotatingAnimationCb!)

By infinite arguments, I meant, as many as your callback function accepts. Otherwise, it will give error in C++ and will ignore extra parameters if working on JS

READ both below:

    // new callbacks based on C++11
#define CC_CALLBACK_0(__selector__,__target__, ...) std::bind(&__selector__,__target__, ##__VA_ARGS__)

#define CC_CALLBACK_1(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, ##__VA_ARGS__)

#define CC_CALLBACK_2(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, std::placeholders::_2, ##__VA_ARGS__)

#define CC_CALLBACK_3(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, ##__VA_ARGS__)

If not understand, let me know.

ok, i am implementing all these,if there any problem i faced i get back to you.

Sure! But you understood the concept, right? :stuck_out_tongue:

truly saying ,first one cleared confusion with second when and how can i use this. :pensive:

Don’t use it. We mostly use CC_CALLBACK_0
Understand the concept. Incase, you want to use it, then only, otherwise, you can do everything you want to do just with C_CALLBACK_0

And I doubt if you read the stackoverflow link I gave.

thanks for your feedback.