zoukankan      html  css  js  c++  java
  • cocos2d中sprite动画接口及动画实现思路总结

    cocos2d中sprite动画接口及动画实现思路总结

    1)延时动作(CCIntervalAction )

    CCDelayTime:延时

    [CCDelayTime actionWithDuration:1]

    CCMoveTo :移动到

    [CCMoveTo actionWithDuration:2 position:ccp(s.width - 50, s.height - 50) ]

    CCMoveBy:移动

    [CCMoveBy actionWithDuration:2 position:ccp(-50, -50)]

    CCJumpTo:跳跃到 -设置终点位置和跳跃癿高度和次数

    [CCJumpTo actionWithDuration:2 position:ccp(150, 50) height:30 jumps:5]

    CCJumpBy :跳跃 – 设置终点位置和跳跃癿高度和次数

    [CCJumpBy actionWithDuration:2 position:ccp(100, 100) height:30 jumps:5]

    CCScaleTo:放大到

    [CCScaleTo actionWithDuration:2 scale:4]

    CCScaleBy:放大

    [CCScaleBy actionWithDuration:2 scale:0.5]

    CCRotateTo:旋转到

    [CCRotateTo actionWithDuration:2 angle:180]

    CCRotateBy:旋转

    [CCRotateBy actionWithDuration:2 angle:-180]

    CCFadeTo:变暗到

    [CCFadeTo actionWithDuration: 1 opacity:80]

    CCFadeIn:由无变亮

    [CCFadeIn actionWithDuration:1.0f]

    CCFadeOut:由亮变无

    [CCFadeOut actionWithDuration:1.0f]

    2)组合动作

    CCSequence:线序排列若干个劢作,然后按先后次序逐个执行

    [CCSequence actions:ac0, ac1, ac2, ac3, ac4, ac0, nil]

    CCSpawn:同时并列执行若干个劢作,但要求劢作都必须 是可以同时执行癿。比如:移劢式翻转、变色、变大小等。

    [CCSpawn actions:ac1, ac2, seq, nil]

    CCRepeat:重复有限次数的动作

    [CCRepeat actionWithAction:seq times:3]

    reverse:反动作就是反向(逆向)执行某个动作,支持针对动作序列的反动作序列不是所有的类都支持反动作,XxxxTo 类通常不支持反动作,XxxxBy 类通常支持

    id ac1 = [CCMoveBy actionWithDuration:2 position:ccp(190, 220)];

    id ac2 = [ac1 reverse];

    CCAnimate:动画就是让精灵自身癿连续执行一段影像,形成模拟运动的效果:行走时的精灵状态、打斗时的状态等

    [CCAnimate actionWithAnimation: animation]

    CCRepeatForever:无限期执行某个动作或动作序列,直到被停止

    [CCRepeatForever actionWithAction:action]

    3)速度变化

    EaseIn: 匀加速

    [CCEaseIn actionWithAction:ac rate:3]

    EaseOut: 匀减速

    [CCEaseOut actionWithAction:ac rate:3]

    EaseInOut: 先匀加速后匀减速

    [CCEaseInOut actionWithAction:ac rate:3]

    EaseSineIn: 变加速(正弦)

    [CCEaseSineIn actionWithAction:ac]

    EaseSineOut: 变减速(正弦)

    [CCEaseSineOut actionWithAction:ac]

    EaseSineInOut: 先变加速后变减速(正弦)

    [CCEaseSineInOut actionWithAction:ac]

    EaseExponentialIn: 变加速(由慢至极快)

    [CCEaseExponentialIn actionWithAction:ac]

    EaseExponentialOut: 变减速(由极快至慢)

    [CCEaseExponentialOut actionWithAction:ac]

    EaseExponentialInOut: 先变加速后变减速(由慢至极快再由极快至慢)

    [CCEaseExponentialInOut actionWithAction:ac]

    4)函数扩展

    通过实现了动作、动作序列的任意扩展和连接。

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

    [CCCallFunc actionWithTarget:self selector:@selector(CallBack1)

    CCCallFuncN-带对象参数 调用自定义函数时,传递当前对象。

    [CCCallFuncN actionWithTarget:self selector:@selector(CallBack2:)

    CCCallFuncND -带对象、数据参数 调用自定义函数时,传递当前对象和一个常量(也可以是指针)。

    [CCCallFuncND actionWithTarget:self selector:@selector(CallBack3:data:) data:(void*)2]

    上面参考知易教程简要介绍了cocos2d中常用的动作接口,下面是我自己总结几种动画实现思路,希望对大家有所帮助。

    1)冰糖葫芦法:像管道工中水管接通后水流过的动画,还有移车位车子的从house1走到house10的动画,这些必须将连贯整体的动画碎片话,最后像冰糖葫芦一样串在一起,每个连节点上计算下一步的状态和入口。

    2)递归法:很多背景动画都是循环播放的,比如白云飘过,鱼儿游过。像这类的动画可以通过在动画回调函数中递归调用自己来实现。

    3)组合运动法:高中物理有介绍任何运动都是可以分解的,比如螺旋运动吧,就可以分解成圆周运动和一个匀速运动。cocos2d中通过CCSpawn组合。

    4)内嵌法:像移车位选管页面中有个气球动画:气球里面有个房间号,房间号是动态变化的,动画要求气球和房间号整体飘动效果)。气球用的是CCSprite,房间号是CCLabel,我们将CCLabel嵌入CCSprite,然后直接操作CCSprite就可以实现整体效果。

     

  • 相关阅读:
    Java程序:从命令行接收多个数字,求和并输出结果
    大道至简读后感
    大道至简第一章读后感Java伪代码
    Creating a SharePoint BCS .NET Connectivity Assembly to Crawl RSS Data in Visual Studio 2010
    声明式验证超时问题
    Error message when you try to modify or to delete an alternate access mapping in Windows SharePoint Services 3.0: "An update conflict has occurred, and you must re-try this action"
    Upgrading or Redeploying SharePoint 2010 Workflows
    Upgrade custom workflow in SharePoint
    SharePoint 2013中Office Web Apps的一次排错
    How to upgrade workflow assembly in MOSS 2007
  • 原文地址:https://www.cnblogs.com/ADaii/p/2868524.html
Copyright © 2011-2022 走看看