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

【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];

}


截图





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值