Confused about how to use CCCallFunc...

Confused about how to use CCCallFunc...
0.0 0


I am REALLY confused about how to use CCCallFunc. I have used many types of callbacks before in C and C++ but this one has alluded me for about 4 hours now…. So any help would be greatly appreciated.

I have a class called “Character” that contains a CCSprite* and a series of CCAction*’s. I have loaded the sprite in correctly, and have filled all the actions with animations from a plist. when I play them one at a time, all is good! When I setup a CCSequence containing just the animations and play that, again all is good! However at the end of the sequence I would really like to call a callback to change to another animation sequence based on flags set during the current sequence. So fairly vanilla stuff. But I cant seem to get the syntax/configuration of the CCCallFunc/CCCallFuncN/CCCallFuncND to work at all…… I am trying to set a member method of “Character” to respond to the call.

Current code setup:
Character is a class
checkForAnimationChange is the member method of Character I wish to call when the sequence finishes

Code I tried and failed:
Note - I tried all 3 flavors of CCCallFunc
Note - I tried both static and non static versions of checkForAnimationChange

  1. CCCallFunc::actionWithTarget(this, callfunc_selector(Character::checkForAnimationChange)); //Wont compile
  2. CCCallFunc::actionWithTarget(NULL, callfunc_selector(Character::checkForAnimationChange)); //This one compiles, ONLY when checkForAnimationChange is not static. Which causes a crash.
  3. void (Character::*ptrToMember)();
    ptrToMember = &Character::checkForAnimationChange;
    CCCallFunc::actionWithTarget(NULL, callfunc_selector(ptrToMember)); //Wont compile
  4. A ton of other ideas that passed through my head over the last 4 hours……

So long story short. How do I setup a CCCallFunc to call a class member method….


CCAction* action2 = CCRepeatForever::actionWithAction(
(CCActionInterval*)(CCSequence::actions((CCActionInterval*)action1->copy()>autorelease,CCCallFuncN::actionWithTarget), NULL))

This works fine for me :slight_smile:
Optionally you can review ActionsTest.cpp sample


Character should inherit directly or indirectly from SelectorProtocol.

You can refer selector_protocol.h for more information.