Cocos2d iphone CCActionCallBlock中的cocos2d V3发送方
与前面的cocos2dv2一样,我想知道CCActionCallBlock中的发送方Cocos2d iphone CCActionCallBlock中的cocos2d V3发送方,cocos2d-iphone,sender,Cocos2d Iphone,Sender,与前面的cocos2dv2一样,我想知道CCActionCallBlock中的发送方 id callFunc = [CCCallFuncN actionWithTarget:self selector:@selector(finishSeq:)]; //V2 style id sequence = [CCSequnece actions: move, callFunc, nil]; [ship runAction:squence]; -(void) finishSeq: (id) sender
id callFunc = [CCCallFuncN actionWithTarget:self selector:@selector(finishSeq:)]; //V2 style
id sequence = [CCSequnece actions: move, callFunc, nil];
[ship runAction:squence];
-(void) finishSeq: (id) sender {
CCSprite* sprite = (CCSprite*) sender;
sprite.opacity = 150;
}
现在在cocos2dv3中,我必须使用一个块并替换callFunc:
id callFunc = [CCActionCallBlock actionWithBlock:^{
//how do I know the sender to change it's opacity ??
}]
在这种情况下,我知道它是“ship”,但我想对不同的对象使用序列。只需将
finishSeq:
方法中的代码添加到块中,如下所示:
id callFunc = [CCActionCallBlock actionWithBlock:^{
ship.opacity = 150;
}];
id sequence = [CCSequnece actions: move, callFunc, nil];
[ship runAction:sequence];
由于您将在目标节点上发出runAction,因此您的块可以使用该节点。在for循环中,从数组中获取节点以运行带有调用块的操作,当前枚举的节点就是需要在块中使用的节点。该块在枚举时“记住”创建它的节点实例。