您的位置:首页 > 移动开发 > Cocos引擎

【iOS-Cocos2d游戏开发】Cocos2d-iPhone动作Action-扩展动作

2012-06-02 19:24 681 查看
【iOS-Cocos2d游戏开发】Cocos2d-iPhone动作Action-扩展动作

扩展动作:我们已经掌握了执行各种各样的动作,也可以按照不同的快慢修改动作执行的时间,Cocos2D-iPhone还提供了针对现有动作的扩展,以实现各种灵活的效果。

 延时动作 – Delay

在动作序列中增加一个时间间歇:

id ac1 = [CCMoveByactionWithDuration:2position:ccp(200,200)];
id ac2 = [ac1 reverse];
// 实现一个等待间歇等待1秒
id action=[CCSequenceactions:ac1,[CCDelayTimeactionWithDuration:1], ac2,
nil];
[sprite runAction:action];

 函数调用

 函数

在动作序列中间或者结束调用某个函数,执行任何需要执行的任务:动作、状态修改等。代码如下:

- (void) OnCallFunc:(id) sender
{
id ac1 = [CCMoveByactionWithDuration:2position:ccp(200,200)];

id ac2 = [ac1 reverse];
//回调函数
id acf = [CCCallFuncactionWithTarget:self
selector:@selector(CallBack1)];
//对应的函数为:(再做一个动作,这就实现了动作、动作序列的任意扩展和连接)

id action=[CCSequence actions:ac1,acf,ac2,nil];
[spriterunAction:action];
}
- (void) CallBack1
{

id action=[CCTintByactionWithDuration:0.5red:255green:0
blue:255];
[spriterunAction:action];
}

 带对象参数

- (void) OnCallFuncN:(id) sender
{
id ac1 = [CCMoveByactionWithDuration:2position:ccp(200,200)];

id ac2 = [ac1 reverse];
//调用自定义函数时,传递当前对象,CallBack2多个冒号
id acf = [CCCallFuncNactionWithTarget:self
selector:@selector(CallBack2:)];

id action=[CCSequence actions:ac1, acf, ac2,nil];
[spriterunAction:action];
}

- (void) CallBack2:(id)sender {
//对应的自定义函数:(这里,我们直接使用了该对象,传递过来的对象)
id action=[CCTintByactionWithDuration:1red:255green:0
blue:255];
[sender
runAction:action];
}

 带对象,数据参数

-(void)OnCallFuncND:(id)sender{
id ac1 = [CCMoveByactionWithDuration:2position:ccp(200,200)];

id ac2 = [ac1 reverse];
//调用自定义函数时,传递当前对象和一个常量(也可以是指针)。
id acf = [CCCallFuncNDactionWithTarget:self
selector:@selector(CallBack3:data:)data:(void*)100];

id action=[CCSequence actions:ac1, acf, ac2,nil];
[spriterunAction:action];
}

-(void) CallBack3:(id)sender data:(void*)data {
//对应的自定义函数,我们使用了传递的对象和数据:
id action=[CCTintByactionWithDuration:(NSInteger)datared:255green:0
blue:255];
[sender
runAction:action];
}

截图



【点我下载源码】
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐