The CCCallFunc Action allows you to call a method from an action. Can be useful at the end of a sequence action.
Example:
id actionTo = [CCMoveTo actionWithDuration: 2 position: ccp(s.width-40, s.height-40)]; id actionBy = [CCMoveBy actionWithDuration: 2 position: ccp(80,80)]; id actionCallFunc = [CCCallFunc actionWithTarget:self selector:@selector(doATask)]; id actionSequence = [CCSequence actions: actionTo, actionBy, actionCallFunc, nil]; -(void) doATask { //some code }
There are two variations of CCCallFunc. They are CCCallFuncN and CCCallFuncND.
CCCallFuncN takes the node as an argument, and CCCallFuncND takes the node and a pointer to some data.
Example:
id actionCallFuncN = [CCCallFuncN actionWithTarget:self selector:@selector(doATaskN:)]; // make sure you notice the trailing : id actionCallFuncND = [CCCallFuncND actionWithTarget:self selector:@selector(doATaskND:data:) data:pointerToSomeData]; - (void) doATaskN: (id)node { //some code } - (void) doATaskND: (id)node data:(void*)d { //some code }
since v0.99.2
// BCA is cocos2d macro that means: Block Copy Autorelease // CCCallBlock (no arguments) id blockAction = [CCCallBlock actionWithBlock:BCA(^{ [label setString:@"Called Block!"]; })]; // CCCallBlockN (passes the Node as an argument) void (^block)(CCNode*) = BCA(^(CCNode *n) { // do something generic with node CCLOG(@"called block for %@", n); }); id blockAction2 = [CCCallBlockN actionWithBlock:block]
since v0.99.2
Simulates a “Camera”. The followed node will be centered.
// create an sprite id sprite = [CCSprite xxxx]; [self addChild:sprite]; [self runAction: [CCFollow actionWithTarget:sprite worldBoundary:CGRectMake(0, 0, (winSize.width*2)-100, winSize.height)]];
since v0.99.2
It's a “generic” action that lets you modify any property of any objective-c class.
// It will modify the "rotation" property from 0 to -270 in 2 seconds, and then it will run the reverse action. id rot = [CCPropertyAction actionWithDuration:2 key:@"rotation" from:0 to:-270]; id rot_back = [rot reverse]; id rot_seq = [CCSequence actions:rot, rot_back, nil];