cocos2d-基本概念(4)-CallFunc Action

CallFunc Action


CallFunc Action 允许你可以在一个action里面调用一个方法。在序列action里面的最后一个调用,会非常有用。 

Example:

id actionTo = [MoveTo actionWithDuration: 2 position:ccp(s.width-40, s.height-40)];

id actionBy = [MoveBy actionWithDuration:2  position: ccp(80,80)];

id actionCallFunc = [CallFunc actionWithTarget:self selector:@selector(doATask)];


id actionSequence = [Sequence actions: actionTo, actionBy, actionCallFunc, nil];


-(void) doATask

{

//some code

}

CallFuncN and CallFuncND Actions


有两种类型的CallFunc,分别是CallFuncN和CallFuncND

 CallFuncN 把node当作参数。

 CallFuncND 需要node和一个指向某个数据的指针。

Example:

id actionCallFuncN = [CallFuncN actionWithTarget:self selector:@selector(doATaskN:)];

// make sure you notice the trailing :

id actionCallFuncND = [CallFuncND actionWithTarget:self selector:@selector(doATaskN:data:) 

data:pointerToSomeData];

- (void) doATaskN: (id)node

{

//some code

}

- (void) doATaskND: (id)node data:(void*)d

{

//some code

}


posted @ 2010-01-24 22:19  AlexLiu  阅读(5193)  评论(0编辑  收藏  举报