Cocos2d-x 2.0变速动画深入分析

发表于2017-08-22
评论0 6.8k浏览

     

       变速动画都是由时间动画所衍生出来的,它是通过对一个匀速动画的进度进行调节来实现的,所以你要运行一个变速动画,首先要给他指定一个匀速动画,播放这个变速动画,它也播放被指定的匀速动画,在变速动画的更新函数中对被指定的匀速动画通过一个变速曲线计算得到相应的播放进度,变速动画停止播放时,被指定的匀速动画也必须被停止。所以,变速动画其实就是一个控制器,用来控制一个匀速动画的播放进度,使其产生变速的效果。

       为了讲述好本节变速动画的内容,我专门写了一个曲线生成工具,这样可以更直观的看到变速曲线的形态。

      打开CActionEase.h:

  1. #ifndef __ACTION_CCEASE_ACTION_H__  
  2. #define __ACTION_CCEASE_ACTION_H__  
  3.   
  4. #include "CCActionInterval.h"  
  5. //使用Cocos2d命名空间  
  6. NS_CC_BEGIN  
  7. //要用到以下两个类  
  8. class CCObject;  
  9. class CCZone;  
  10.   
  11. //所有变速动画的基类。  
  12. class CC_DLL CCActionEase : public CCActionInterval  
  13. {  
  14. public:  
  15.     //析构  
  16.     virtual ~CCActionEase(void);  
  17.   
  18.     //初始化动画,参数为一个匀速时间动画。  
  19.     bool initWithAction(CCActionInterval *pAction);  
  20.     //产生一个当前实例的拷贝。  
  21.   virtual CCObject* copyWithZone(CCZone* pZone);  
  22.   //指定演示当前动画的演员。  
  23.   virtual void startWithTarget(CCNode *pTarget);  
  24.   //停止当前动画。  
  25.   virtual void stop(void);  
  26.   //更新动画。  
  27.   virtual void update(float time);  
  28.    //创建一个反向播放的当前动画。  
  29.    virtual CCActionInterval* reverse(void);  
  30.   
  31. public:  
  32.     //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  33.     CC_DEPRECATED_ATTRIBUTE static CCActionEase* actionWithAction(CCActionInterval *pAction);  
  34.   
  35.     //同上  
  36.     static CCActionEase* create(CCActionInterval *pAction);  
  37.   
  38. protected:  
  39.     //保存对应的匀速动画。  
  40.     CCActionInterval *m_pOther;  
  41. };  

对应CPP:


  1. //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  2. CCActionEase* CCActionEase::actionWithAction(CCActionInterval *pAction)  
  3. {  
  4.     return CCActionEase::create(pAction);  
  5. }  
  6. //同上  
  7. CCActionEase* CCActionEase::create(CCActionInterval *pAction)  
  8. {  
  9.   //使用new创建一个当前类实例.  
  10.     CCActionEase *pRet = new CCActionEase();  
  11.     if (pRet)  
  12.    {  
  13.      //初始化.  
  14.         if (pRet->initWithAction(pAction))  
  15.         {  
  16.    //交由内存管理器进行释放管理.  
  17.             pRet->autorelease();  
  18.         }  
  19.         else  
  20.         {  
  21.    //如果初始化失败,则直接释放  
  22.             CC_SAFE_RELEASE_NULL(pRet);  
  23.         }  
  24.     }  
  25.   //返回创建的实例.  
  26.     return pRet;  
  27. }  
  28. //初始化.  
  29. bool CCActionEase::initWithAction(CCActionInterval *pAction)  
  30. {  
  31.   //有效性判断.  
  32.     CCAssert(pAction != NULL, "");  
  33.   //先调用基类的初始化函数.  
  34.     if (CCActionInterval::initWithDuration(pAction->getDuration()))  
  35.    {  
  36.      //如果成功保存参数动画,本着"占用就加1"的原则,对其引用计数加一.  
  37.         m_pOther = pAction;  
  38.         pAction->retain();  
  39.   
  40.         return true;  
  41.     }  
  42.   
  43.     return false;  
  44. }  
  45. //产生一个当前类的实例拷贝.  
  46. CCObject* CCActionEase::copyWithZone(CCZone *pZone)  
  47. {  
  48.   //  
  49.     CCZone* pNewZone = NULL;  
  50.     CCActionEase* pCopy = NULL;  
  51.     //判断参数有效以及其内部已经有创建好的拷贝。  
  52.   if(pZone && pZone->m_pCopyObject)   
  53.     {  
  54.         //直接强转后返回这个创建好的拷贝。  
  55.         pCopy = (CCActionEase*)(pZone->m_pCopyObject);  
  56.     }  
  57.     else  
  58.    {  
  59.      //如果无效,新创建一个当前类实例,并创建一个用于拷贝的类实例,将当前类实例设为拷贝类实例的内部拷贝,其实就是建立一个通用的拷贝对象,它内部有一个万物基类CCObject的指针,用来保存各个派生类的实例对象。  
  60.         pCopy = new CCActionEase();  
  61.         pZone = pNewZone = new CCZone(pCopy);  
  62.     }  
  63.   //先调用基类的相应函数对其进行基类属性的相关初始化,这个函数会一层层调用当前类基类直至CCAction的相应函数。  
  64.     CCActionInterval::copyWithZone(pZone);  
  65.   //使用保存的匀速动画来初始化拷贝实例。  
  66.     pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()));  
  67.     //释放通用的拷贝对象。  
  68.     CC_SAFE_DELETE(pNewZone);  
  69.     return pCopy;  
  70. }  
  71. //析构  
  72. CCActionEase::~CCActionEase(void)  
  73. {  
  74.   //释放占用的匀速动画实例。  
  75.     CC_SAFE_RELEASE(m_pOther);  
  76. }  
  77.   
  78. //指定演示当前动画的演员。  
  79. void CCActionEase::startWithTarget(CCNode *pTarget)  
  80. {  
  81.   //调用基类的相应函数。  
  82.    CCActionInterval::startWithTarget(pTarget);  
  83.    //设定匀速动画的演员。  
  84.     m_pOther->startWithTarget(m_pTarget);  
  85. }  
  86. //停止当前动画。  
  87. void CCActionEase::stop(void)  
  88. {  
  89.   //让匀速动画停止播放。  
  90.    m_pOther->stop();  
  91.    //调用基类的相应函数停止当前动画。  
  92.     CCActionInterval::stop();  
  93. }  
  94. //更新动画。  
  95. void CCActionEase::update(float time)  
  96. {  
  97.   //更新匀速动画。  
  98.     m_pOther->update(time);  
  99. }  
  100. //创建一个反向播放的变速动画。  
  101. CCActionInterval* CCActionEase::reverse(void)  
  102. {  
  103.   //通过创建一个反向播放的匀速动画做为参数来创建相应的变速动画。  
  104.     return CCActionEase::create(m_pOther->reverse());  
  105. }  

       上面只是一个基类,它并未真正的提供速度的变化调节,下面还有一个基类,提供了一个速度调节系数值。

  1. //可以设定速度的变速动画基类。  
  2. class CC_DLL CCEaseRateAction : public CCActionEase  
  3. {  
  4. public:  
  5.     //析构函数。  
  6.     virtual ~CCEaseRateAction(void);  
  7.   
  8.     //设置速度调节系数。  
  9.     inline void setRate(float rate) { m_fRate = rate; }  
  10.     //取得速度调节系数。  
  11.     inline float getRate(void) { return m_fRate; }  
  12.   
  13.     //初始化当前动画。  
  14.     bool initWithAction(CCActionInterval *pAction, float fRate);  
  15.     //创建一个当前动画的实例拷贝。  
  16.    virtual CCObject* copyWithZone(CCZone* pZone);  
  17.    //创建一个反向播放的当前动画。  
  18.     virtual CCActionInterval* reverse(void);  
  19.   
  20. public:  
  21.     //静态函数:创建对应匀速动画的变速动画,参数一为一个匀速动画。参数二为速度。内部调用create实现。  
  22.     CC_DEPRECATED_ATTRIBUTE static CCEaseRateAction* actionWithAction(CCActionInterval* pAction, float fRate);  
  23.   
  24.    //同上。  
  25.     static CCEaseRateAction* create(CCActionInterval* pAction, float fRate);  
  26.   
  27. protected:  
  28.     //保存速度调节系数值。  
  29.     float m_fRate;  
  30. };  

CPP实现:


  1.  //静态函数:创建对应匀速动画的变速动画,参数一为一个匀速动画。参数二为速度。内部调用create实现。  
  2. CCEaseRateAction* CCEaseRateAction::actionWithAction(CCActionInterval *pAction, float fRate)  
  3. {  
  4.     return CCEaseRateAction::create(pAction, fRate);  
  5. }  
  6. //同上。  
  7. CCEaseRateAction* CCEaseRateAction::create(CCActionInterval *pAction, float fRate)  
  8. {  
  9.   //先创建相应的变速动画。  
  10.     CCEaseRateAction *pRet = new CCEaseRateAction();  
  11.     if (pRet)  
  12.    {  
  13.      //如果成功,进行初始化后交由内存管理器处理。  
  14.         if (pRet->initWithAction(pAction, fRate))  
  15.         {  
  16.             pRet->autorelease();  
  17.         }  
  18.         else  
  19.         {  
  20.   //如果失败,释放并置空。  
  21.             CC_SAFE_RELEASE_NULL(pRet);  
  22.         }  
  23.     }  
  24.   
  25.     return pRet;  
  26. }  
  27.   
  28. //初始化函数。  
  29. bool CCEaseRateAction::initWithAction(CCActionInterval *pAction, float fRate)  
  30. {  
  31.   //调用基类的初始化处理。  
  32.     if (CCActionEase::initWithAction(pAction))  
  33.    {  
  34.      //保存速度。  
  35.         m_fRate = fRate;  
  36.         return true;  
  37.     }  
  38.   
  39.     return false;  
  40. }  
  41.   
  42. //产生一个当前类的实例拷贝。参见基类的解释。  
  43. CCObject* CCEaseRateAction::copyWithZone(CCZone *pZone)  
  44. {  
  45.     CCZone* pNewZone = NULL;  
  46.     CCEaseRateAction* pCopy = NULL;  
  47.     if(pZone && pZone->m_pCopyObject)   
  48.     {  
  49.         //in case of being called at sub class  
  50.         pCopy = (CCEaseRateAction*)(pZone->m_pCopyObject);  
  51.     }  
  52.     else  
  53.     {  
  54.         pCopy = new CCEaseRateAction();  
  55.         pNewZone = new CCZone(pCopy);  
  56.     }  
  57.   
  58.     pCopy->initWithAction((CCActionInterval*)(m_pOther->copy()->autorelease()), m_fRate);  
  59.   
  60.     CC_SAFE_DELETE(pNewZone);  
  61.     return pCopy;  
  62. }  
  63.   
  64. //析构  
  65. CCEaseRateAction::~CCEaseRateAction(void)  
  66. {  
  67. }  
  68. //创建一个反向播放的变速动画。  
  69. CCActionInterval* CCEaseRateAction::reverse(void)  
  70. {  
  71.     return CCEaseRateAction::create(m_pOther->reverse(), 1 / m_fRate);  
  72. }  

       第二个类有了速度属性,但这个速度属性并未对动画起任何作用。后面的类由这个带速度属性的动画基类派生,真正实现相应的变速效果。


  1. //由快变慢的变速动画。  
  2. class CC_DLL CCEaseIn : public CCEaseRateAction  
  3. {  
  4. public:  
  5.     //更新动画。  
  6.    virtual void update(float time);  
  7.    //创建一个反向播放的当前动画。  
  8.    virtual CCActionInterval* reverse(void);  
  9.    //创建一个当前动画的实例拷贝。  
  10.     virtual CCObject* copyWithZone(CCZone* pZone);  
  11. public:  
  12.    //静态函数:创建对应匀速动画的变速动画,参数一为一个匀速动画。参数二为速度。内部调用create实现。  
  13.      CC_DEPRECATED_ATTRIBUTE static CCEaseIn* actionWithAction(CCActionInterval* pAction, float fRate);  
  14.   
  15.      //同上。  
  16.     static CCEaseIn* create(CCActionInterval* pAction, float fRate);  
  17. };  

CPP:


  1. //静态函数:创建对应匀速动画的变速动画,参数一为一个匀速动画。参数二为速度。内部调用create实现。  
  2. CCEaseIn* CCEaseIn::actionWithAction(CCActionInterval *pAction, float fRate)  
  3. {  
  4.     return CCEaseIn::create(pAction, fRate);  
  5. }  
  6. //同上,参见CCEaseRateAction的create函数。  
  7. CCEaseIn* CCEaseIn::create(CCActionInterval *pAction, float fRate)  
  8. {  
  9.     CCEaseIn *pRet = new CCEaseIn();  
  10.     if (pRet)  
  11.     {  
  12.         if (pRet->initWithAction(pAction, fRate))  
  13.         {  
  14.             pRet->autorelease();  
  15.         }  
  16.         else  
  17.         {  
  18.             CC_SAFE_RELEASE_NULL(pRet);  
  19.         }  
  20.     }  
  21.   
  22.     return pRet;  
  23. }  
  24. //产生一个当前类的实例的拷贝,参见CCEaseRateAction的相应函数。  
  25. CCObject* CCEaseIn::copyWithZone(CCZone *pZone)  
  26. {  
  27.     CCZone* pNewZone = NULL;  
  28.     CCEaseIn* pCopy = NULL;  
  29.     if(pZone && pZone->m_pCopyObject)   
  30.     {  
  31.         //in case of being called at sub class  
  32.         pCopy = (CCEaseIn*)(pZone->m_pCopyObject);  
  33.     }  
  34.     else  
  35.     {  
  36.         pCopy = new CCEaseIn();  
  37.         pNewZone = new CCZone(pCopy);  
  38.     }  
  39.   
  40.     pCopy->initWithAction((CCActionInterval*)(m_pOther->copy()->autorelease()), m_fRate);  
  41.   
  42.     CC_SAFE_DELETE(pNewZone);  
  43.     return pCopy;  
  44. }  
  45. //更新动画。  
  46. void CCEaseIn::update(float time)  
  47. {  
  48.   //这里使用了一个浮点的m_fRate次方计算,time值在0~1间变化,但使用powf(time,m_fRate)会在第一象限生成一个曲线。  
  49.    m_pOther->update(powf(time, m_fRate));  
  50.    //后面的图把m_fRate在0.1到10之间的曲线表现出来,其中X方向代表的是time,也就是进度,系数值就是m_fRate,红色线代表了powf(time,m_fRate)函数。大家可以看到,在m_fRate小于1时函数是先很短时间内达到接近1之后的增速越来越慢,大于1时函数是开始基本都不递增,到后面增速加快,最后非常快。  
  51. }  
  52.   
  53. //创建一个反向播放的变速动画。  
  54. CCActionInterval*   CCEaseIn::reverse(void)  
  55. {  
  56.        return       CCEaseIn::create(m_pOther->reverse(),m_fRate);  
  57. }  



  1. //由慢变快的变速动画,与上个类基个相同,只是在更新函数中速度值不同。  
  2. class CC_DLL CCEaseOut : public CCEaseRateAction  
  3. {  
  4. public:  
  5.    //更新动画。  
  6.    virtual void update(float time);  
  7.    //创建一个反向播放的当前动画。  
  8.    virtual CCActionInterval* reverse(void);  
  9.    //创建一个当前动画的实例拷贝。  
  10.     virtual CCObject* copyWithZone(CCZone* pZone);  
  11.   
  12. public:  
  13.    //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  14.     CC_DEPRECATED_ATTRIBUTE static CCEaseOut* actionWithAction(CCActionInterval* pAction, float fRate);  
  15.   
  16.      //同上。  
  17.     static CCEaseOut* create(CCActionInterval* pAction, float fRate);  
  18. };  

CPP:
  1. //静态函数:创建对应匀速动画的变速动画,参数一为一个匀速动画。参数二为速度。内部调用create实现。  
  2. CCEaseOut* CCEaseOut::actionWithAction(CCActionInterval *pAction, float fRate)  
  3. {  
  4.     return CCEaseOut::create(pAction, fRate);  
  5. }  
  6. //同上。  
  7. CCEaseOut* CCEaseOut::create(CCActionInterval *pAction, float fRate)  
  8. {  
  9.     CCEaseOut *pRet = new CCEaseOut();  
  10.     if (pRet)  
  11.     {  
  12.         if (pRet->initWithAction(pAction, fRate))  
  13.         {  
  14.             pRet->autorelease();  
  15.         }  
  16.         else  
  17.         {  
  18.             CC_SAFE_RELEASE_NULL(pRet);  
  19.         }  
  20.     }  
  21.   
  22.     return pRet;     
  23. }  
  24. //产生一个当前类的实例拷贝  
  25. CCObject* CCEaseOut::copyWithZone(CCZone *pZone)  
  26. {  
  27.     CCZone* pNewZone = NULL;  
  28.     CCEaseOut* pCopy = NULL;  
  29.     if(pZone && pZone->m_pCopyObject)   
  30.     {  
  31.         //in case of being called at sub class  
  32.         pCopy = (CCEaseOut*)(pZone->m_pCopyObject);  
  33.     }  
  34.     else  
  35.     {  
  36.         pCopy = new CCEaseOut();  
  37.         pNewZone = new CCZone(pCopy);  
  38.     }  
  39.   
  40.     pCopy->initWithAction((CCActionInterval*)(m_pOther->copy()->autorelease()), m_fRate);  
  41.   
  42.     CC_SAFE_DELETE(pNewZone);  
  43.     return pCopy;  
  44. }  
  45. //更新函数。  
  46. void CCEaseOut::update(float time)  
  47. {  
  48.   //本动画与上面的动画相似。我也给出曲线图:  
  49.     m_pOther->update(powf(time, 1 / m_fRate));  
  50. }  
  51. //创建一个反向播放的变速动画。  
  52. CCActionInterval* CCEaseOut::reverse()  
  53. {  
  54.     return CCEaseOut::create(m_pOther->reverse(), 1 / m_fRate);  
  55. }  

copy

  1. class CC_DLL CCEaseInOut : public CCEaseRateAction  
  2. {  
  3. public:  
  4.    //更新动画。  
  5.    virtual void update(float time);  
  6.    //创建一个反向播放的当前动画。  
  7.    virtual CCActionInterval* reverse(void);  
  8.    //创建一个当前动画的实例拷贝。  
  9.     virtual CCObject* copyWithZone(CCZone* pZone);  
  10.   
  11. public:  
  12.   //静态函数:创建对应匀速动画的变速动画,参数一为一个匀速动画。参数二为速度。内部调用create实现。  
  13.     CC_DEPRECATED_ATTRIBUTE static CCEaseInOut* actionWithAction(CCActionInterval* pAction, float fRate);  
  14.   
  15.      //同上。  
  16.     static CCEaseInOut* create(CCActionInterval* pAction, float fRate);  
  17. };  
  18. //静态函数:创建对应匀速动画的变速动画,参数一为一个匀速动画。参数二为速度。内部调用create实现。  
  19. CCEaseInOut* CCEaseInOut::actionWithAction(CCActionInterval *pAction, float fRate)  
  20. {  
  21.     return CCEaseInOut::create(pAction, fRate);  
  22. }  
  23. //同上  
  24. CCEaseInOut* CCEaseInOut::create(CCActionInterval *pAction, float fRate)  
  25. {  
  26.     CCEaseInOut *pRet = new CCEaseInOut();  
  27.     if (pRet)  
  28.     {  
  29.         if (pRet->initWithAction(pAction, fRate))  
  30.         {  
  31.             pRet->autorelease();  
  32.         }  
  33.         else  
  34.         {  
  35.             CC_SAFE_RELEASE_NULL(pRet);  
  36.         }  
  37.     }  
  38.   
  39.     return pRet;   
  40. }  
  41. //创建一个当前类的实例拷贝。  
  42. CCObject* CCEaseInOut::copyWithZone(CCZone *pZone)  
  43. {  
  44.     CCZone* pNewZone = NULL;  
  45.     CCEaseInOut* pCopy = NULL;  
  46.     if(pZone && pZone->m_pCopyObject)   
  47.     {  
  48.         //in case of being called at sub class  
  49.         pCopy = (CCEaseInOut*)(pZone->m_pCopyObject);  
  50.     }  
  51.     else  
  52.     {  
  53.         pCopy = new CCEaseInOut();  
  54.         pNewZone = new CCZone(pCopy);  
  55.     }  
  56.   
  57.     pCopy->initWithAction((CCActionInterval*)(m_pOther->copy()->autorelease()), m_fRate);  
  58.   
  59.     CC_SAFE_DELETE(pNewZone);  
  60.     return pCopy;  
  61. }  
  62.   
  63. //更新动画的函数。  
  64. void CCEaseInOut::update(float time)  
  65. {  
  66.   //这个曲线稍复杂,继续上图  
  67.     time *= 2;  
  68.     if (time < 1)  
  69.     {  
  70.         m_pOther->update(0.5f * powf(time, m_fRate));  
  71.     }  
  72.     else  
  73.     {  
  74.         m_pOther->update(1.0f - 0.5f * powf(2-time, m_fRate));  
  75.     }  
  76. }  
  77. //创建一个反向播放的变速动画。  
  78. CCActionInterval* CCEaseInOut::reverse(void)  
  79. {  
  80.     return CCEaseInOut::create(m_pOther->reverse(), m_fRate);  
  81. }  

copy

  1. class CC_DLL CCEaseExponentialIn : public CCActionEase  
  2. {  
  3. public:  
  4.     //更新动画。  
  5.    virtual void update(float time);  
  6.    //创建一个反向播放的当前动画。  
  7.    virtual CCActionInterval* reverse(void);  
  8.    //创建一个当前动画的实例拷贝。  
  9.     virtual CCObject* copyWithZone(CCZone* pZone);  
  10.   
  11. public:  
  12.     //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  13.     CC_DEPRECATED_ATTRIBUTE static CCEaseExponentialIn* actionWithAction(CCActionInterval* pAction);  
  14.      //同上。  
  15.     static CCEaseExponentialIn* create(CCActionInterval* pAction);  
  16. };  
  17. //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  18. CCEaseExponentialIn* CCEaseExponentialIn::actionWithAction(CCActionInterval* pAction)  
  19. {  
  20.     return CCEaseExponentialIn::create(pAction);  
  21. }  
  22. //同上。  
  23. CCEaseExponentialIn* CCEaseExponentialIn::create(CCActionInterval* pAction)  
  24. {  
  25.     CCEaseExponentialIn *pRet = new CCEaseExponentialIn();  
  26.     if (pRet)  
  27.     {  
  28.         if (pRet->initWithAction(pAction))  
  29.         {  
  30.             pRet->autorelease();  
  31.         }  
  32.         else  
  33.         {  
  34.             CC_SAFE_RELEASE_NULL(pRet);  
  35.         }  
  36.     }  
  37.   
  38.     return pRet;      
  39. }  
  40. //创建一个当前类的实例拷贝。  
  41. CCObject* CCEaseExponentialIn::copyWithZone(CCZone *pZone)  
  42. {  
  43.     CCZone* pNewZone = NULL;  
  44.     CCEaseExponentialIn* pCopy = NULL;  
  45.     if(pZone && pZone->m_pCopyObject)   
  46.     {  
  47.         //in case of being called at sub class  
  48.         pCopy = (CCEaseExponentialIn*)(pZone->m_pCopyObject);  
  49.     }  
  50.     else  
  51.     {  
  52.         pCopy = new CCEaseExponentialIn();  
  53.         pNewZone = new CCZone(pCopy);  
  54.     }  
  55.   
  56.     pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()));  
  57.       
  58.     CC_SAFE_DELETE(pNewZone);  
  59.     return pCopy;  
  60. }  
  61.   
  62. //更新动画。  
  63. void CCEaseExponentialIn::update(float time)  
  64. {  
  65.   //不废话,上曲线,此曲线没有系数。是固定曲线。  
  66.     m_pOther->update(time == 0 ? 0 : powf(2, 10 * (time/1 - 1)) - 1 * 0.001f);  
  67. }  
  68.   
  69. //创建一个反向播放的变速动画。  
  70. CCActionInterval* CCEaseExponentialIn::reverse(void)  
  71. {  
  72.     return CCEaseExponentialOut::create(m_pOther->reverse());  
  73. }  


copy

  1. class CC_DLL CCEaseExponentialOut : public CCActionEase  
  2. {  
  3. public:  
  4.     //更新动画。  
  5.    virtual void update(float time);  
  6.    //创建一个反向播放的当前动画。  
  7.    virtual CCActionInterval* reverse(void);  
  8.    //创建一个当前动画的实例拷贝。  
  9.     virtual CCObject* copyWithZone(CCZone* pZone);  
  10.   
  11. public:  
  12.    //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  13.     CC_DEPRECATED_ATTRIBUTE static CCEaseExponentialOut* actionWithAction(CCActionInterval* pAction);  
  14.      //同上。  
  15.     static CCEaseExponentialOut* create(CCActionInterval* pAction);  
  16. };  
  17. //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  18. CCEaseExponentialOut* CCEaseExponentialOut::actionWithAction(CCActionInterval* pAction)  
  19. {  
  20.     return CCEaseExponentialOut::create(pAction);  
  21. }  
  22.  //同上。  
  23. CCEaseExponentialOut* CCEaseExponentialOut::create(CCActionInterval* pAction)  
  24. {  
  25.     CCEaseExponentialOut *pRet = new CCEaseExponentialOut();  
  26.     if (pRet)  
  27.     {  
  28.         if (pRet->initWithAction(pAction))  
  29.         {  
  30.             pRet->autorelease();  
  31.         }  
  32.         else  
  33.         {  
  34.             CC_SAFE_RELEASE_NULL(pRet);  
  35.         }  
  36.     }  
  37.   
  38.     return pRet;   
  39. }  
  40. //创建一个当前动画的实例拷贝。  
  41. CCObject* CCEaseExponentialOut::copyWithZone(CCZone *pZone)  
  42. {  
  43.     CCZone* pNewZone = NULL;  
  44.     CCEaseExponentialOut* pCopy = NULL;  
  45.     if(pZone && pZone->m_pCopyObject)   
  46.     {  
  47.         //in case of being called at sub class  
  48.         pCopy = (CCEaseExponentialOut*)(pZone->m_pCopyObject);  
  49.     }  
  50.     else  
  51.     {  
  52.         pCopy = new CCEaseExponentialOut();  
  53.         pNewZone = new CCZone(pCopy);  
  54.     }  
  55.   
  56.     pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()));  
  57.       
  58.     CC_SAFE_DELETE(pNewZone);  
  59.     return pCopy;  
  60. }  
  61. //更新函数。  
  62. void CCEaseExponentialOut::update(float time)  
  63. {  
  64.   //上曲线说明,此曲线没有系数。是固定曲线。  
  65.     
  66.     m_pOther->update(time == 1 ? 1 : (-powf(2, -10 * time / 1)   1));  
  67. }  
  68. //创建一个反向播放的当前动画。  
  69. CCActionInterval* CCEaseExponentialOut::reverse(void)  
  70. {  
  71.     return CCEaseExponentialIn::create(m_pOther->reverse());  
  72. }  




  1. class CC_DLL CCEaseExponentialInOut : public CCActionEase  
  2. {  
  3. public:  
  4.     //更新动画。  
  5.    virtual void update(float time);  
  6.    //创建一个反向播放的当前动画。  
  7.    virtual CCActionInterval* reverse(void);  
  8.    //创建一个当前动画的实例拷贝。  
  9.     virtual CCObject* copyWithZone(CCZone* pZone);  
  10. public:  
  11.    //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  12.     CC_DEPRECATED_ATTRIBUTE static CCEaseExponentialInOut* actionWithAction(CCActionInterval* pAction);  
  13.   
  14.    //同上。  
  15.     static CCEaseExponentialInOut* create(CCActionInterval* pAction);  
  16. };  
  17. //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  18. CCEaseExponentialInOut* CCEaseExponentialInOut::actionWithAction(CCActionInterval *pAction)  
  19. {  
  20.     return CCEaseExponentialInOut::create(pAction);  
  21. }  
  22. //同上。  
  23. CCEaseExponentialInOut* CCEaseExponentialInOut::create(CCActionInterval *pAction)  
  24. {  
  25.     CCEaseExponentialInOut *pRet = new CCEaseExponentialInOut();  
  26.     if (pRet)  
  27.     {  
  28.         if (pRet->initWithAction(pAction))  
  29.         {  
  30.             pRet->autorelease();  
  31.         }  
  32.         else  
  33.         {  
  34.             CC_SAFE_RELEASE_NULL(pRet);  
  35.         }  
  36.     }  
  37.   
  38.     return pRet;   
  39. }  
  40. //创建一个当前动画的实例拷贝。  
  41. CCObject* CCEaseExponentialInOut::copyWithZone(CCZone *pZone)  
  42. {  
  43.     CCZone* pNewZone = NULL;  
  44.     CCEaseExponentialInOut* pCopy = NULL;  
  45.     if(pZone && pZone->m_pCopyObject)   
  46.     {  
  47.         //in case of being called at sub class  
  48.         pCopy = (CCEaseExponentialInOut*)(pZone->m_pCopyObject);  
  49.     }  
  50.     else  
  51.     {  
  52.         pCopy = new CCEaseExponentialInOut();  
  53.         pNewZone = new CCZone(pCopy);  
  54.     }  
  55.   
  56.     pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()));  
  57.       
  58.     CC_SAFE_DELETE(pNewZone);  
  59.     return pCopy;  
  60. }  
  61. //动画更新。  
  62. void CCEaseExponentialInOut::update(float time)  
  63. {  
  64.   //上曲线,没有系数,固定曲线  
  65.     
  66.     time /= 0.5f;  
  67.     if (time < 1)  
  68.     {  
  69.         time = 0.5f * powf(2, 10 * (time - 1));  
  70.     }  
  71.     else  
  72.     {  
  73.         time = 0.5f * (-powf(2, -10 * (time - 1))   2);  
  74.     }  
  75.   
  76.     m_pOther->update(time);  
  77. }  
  78. //创建一个反向播放的当前动画。  
  79. CCActionInterval* CCEaseExponentialInOut::reverse()  
  80. {  
  81.     return CCEaseExponentialInOut::create(m_pOther->reverse());  
  82. }  



  1. //cos曲线方式变化的变速动画。  
  2. class CC_DLL CCEaseSineIn : public CCActionEase  
  3. {  
  4. public:  
  5.     //更新动画。  
  6.    virtual void update(float time);  
  7.    //创建一个反向播放的当前动画。  
  8.    virtual CCActionInterval* reverse(void);  
  9.    //创建一个当前动画的实例拷贝。  
  10.     virtual CCObject* copyWithZone(CCZone* pZone);  
  11.   
  12. public:  
  13.    //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  14.     CC_DEPRECATED_ATTRIBUTE static CCEaseSineIn* actionWithAction(CCActionInterval* pAction);  
  15.     //同上  
  16.     static CCEaseSineIn* create(CCActionInterval* pAction);  
  17. };  
  18. //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  19. CCEaseSineIn* CCEaseSineIn::actionWithAction(CCActionInterval* pAction)  
  20. {  
  21.     return CCEaseSineIn::create(pAction);  
  22. }  
  23. //同上  
  24. CCEaseSineIn* CCEaseSineIn::create(CCActionInterval* pAction)  
  25. {  
  26.     CCEaseSineIn *pRet = new CCEaseSineIn();  
  27.     if (pRet)  
  28.     {  
  29.         if (pRet->initWithAction(pAction))  
  30.         {  
  31.             pRet->autorelease();  
  32.         }  
  33.         else  
  34.         {  
  35.             CC_SAFE_RELEASE_NULL(pRet);  
  36.         }  
  37.     }  
  38.   
  39.     return pRet;   
  40. }  
  41. //创建一个当前动画的实例拷贝。  
  42. CCObject* CCEaseSineIn::copyWithZone(CCZone *pZone)  
  43. {  
  44.     CCZone* pNewZone = NULL;  
  45.     CCEaseSineIn* pCopy = NULL;  
  46.     if(pZone && pZone->m_pCopyObject)  
  47.     {  
  48.         //in case of being called at sub class  
  49.         pCopy = (CCEaseSineIn*)(pZone->m_pCopyObject);  
  50.     }  
  51.     else  
  52.     {  
  53.         pCopy = new CCEaseSineIn();  
  54.         pNewZone = new CCZone(pCopy);  
  55.     }  
  56.   
  57.     pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()));  
  58.       
  59.     CC_SAFE_DELETE(pNewZone);  
  60.     return pCopy;  
  61. }  
  62. //更新  
  63. void CCEaseSineIn::update(float time)  
  64. {   //上曲线图,无需参数,固定曲线:  
  65.     
  66.     m_pOther->update(-1 * cosf(time * (float)M_PI_2)   1);  
  67. }  
  68. //创建一个反向播放的当前动画。  
  69. CCActionInterval* CCEaseSineIn::reverse(void)  
  70. {  
  71.     return CCEaseSineOut::create(m_pOther->reverse());  
  72. }  



  1. //sin曲线方式变化的变速动画。  
  2. class CC_DLL CCEaseSineOut : public CCActionEase  
  3. {  
  4. public:  
  5.     //更新动画。  
  6.    virtual void update(float time);  
  7.    //创建一个反向播放的当前动画。  
  8.    virtual CCActionInterval* reverse(void);  
  9.    //创建一个当前动画的实例拷贝。  
  10.     virtual CCObject* copyWithZone(CCZone* pZone);  
  11.   
  12. public:  
  13.    //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  14.     CC_DEPRECATED_ATTRIBUTE static CCEaseSineOut* actionWithAction(CCActionInterval* pAction);  
  15.     //同上  
  16.     static CCEaseSineOut* create(CCActionInterval* pAction);  
  17. };  
  18. //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  19. CCEaseSineOut* CCEaseSineOut::actionWithAction(CCActionInterval* pAction)  
  20. {  
  21.     return CCEaseSineOut::create(pAction);  
  22. }  
  23. //同上  
  24. CCEaseSineOut* CCEaseSineOut::create(CCActionInterval* pAction)  
  25. {  
  26.     CCEaseSineOut *pRet = new CCEaseSineOut();  
  27.     if (pRet)  
  28.     {  
  29.         if (pRet->initWithAction(pAction))  
  30.         {  
  31.             pRet->autorelease();  
  32.         }  
  33.         else  
  34.         {  
  35.             CC_SAFE_RELEASE_NULL(pRet);  
  36.         }  
  37.     }  
  38.   
  39.     return pRet;   
  40. }  
  41. //创建一个当前动画的实例拷贝。  
  42. CCObject* CCEaseSineOut::copyWithZone(CCZone *pZone)  
  43. {  
  44.     CCZone* pNewZone = NULL;  
  45.     CCEaseSineOut* pCopy = NULL;  
  46.     if(pZone && pZone->m_pCopyObject)   
  47.     {  
  48.         //in case of being called at sub class  
  49.         pCopy = (CCEaseSineOut*)(pZone->m_pCopyObject);  
  50.     }  
  51.     else  
  52.     {  
  53.         pCopy = new CCEaseSineOut();  
  54.         pNewZone = new CCZone(pCopy);  
  55.     }  
  56.   
  57.     pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()));  
  58.       
  59.     CC_SAFE_DELETE(pNewZone);  
  60.     return pCopy;  
  61. }  
  62. //更新  
  63. void CCEaseSineOut::update(float time)  
  64. {  
  65.   //上图说明:  
  66.     
  67.     m_pOther->update(sinf(time * (float)M_PI_2));  
  68. }  
  69. //创建一个反向播放的当前动画。  
  70. CCActionInterval* CCEaseSineOut::reverse(void)  
  71. {  
  72.     return CCEaseSineIn::create(m_pOther->reverse());  
  73. }  




  1. //另种cos曲线方式变化的变速动画。  
  2. class CC_DLL CCEaseSineInOut : public CCActionEase  
  3. {  
  4. public:  
  5.     //更新动画。  
  6.    virtual void update(float time);  
  7.    //创建一个反向播放的当前动画。  
  8.    virtual CCActionInterval* reverse(void);  
  9.    //创建一个当前动画的实例拷贝。  
  10.     virtual CCObject* copyWithZone(CCZone* pZone);  
  11.   
  12. public:  
  13.    //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  14.     CC_DEPRECATED_ATTRIBUTE static CCEaseSineInOut* actionWithAction(CCActionInterval* pAction);  
  15.    //同上  
  16.     static CCEaseSineInOut* create(CCActionInterval* pAction);  
  17. };  
  18.   
  19. //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  20. CCEaseSineInOut* CCEaseSineInOut::actionWithAction(CCActionInterval* pAction)  
  21. {  
  22.     return CCEaseSineInOut::create(pAction);  
  23. }  
  24. //同上  
  25. CCEaseSineInOut* CCEaseSineInOut::create(CCActionInterval* pAction)  
  26. {  
  27.     CCEaseSineInOut *pRet = new CCEaseSineInOut();  
  28.     if (pRet)  
  29.     {  
  30.         if (pRet->initWithAction(pAction))  
  31.         {  
  32.             pRet->autorelease();  
  33.         }  
  34.         else  
  35.         {  
  36.             CC_SAFE_RELEASE_NULL(pRet);  
  37.         }  
  38.     }  
  39.   
  40.     return pRet;   
  41. }  
  42. //创建一个当前动画的实例拷贝。  
  43. CCObject* CCEaseSineInOut::copyWithZone(CCZone *pZone)  
  44. {  
  45.     CCZone* pNewZone = NULL;  
  46.     CCEaseSineInOut* pCopy = NULL;  
  47.     if(pZone && pZone->m_pCopyObject)   
  48.     {  
  49.         //in case of being called at sub class  
  50.         pCopy = (CCEaseSineInOut*)(pZone->m_pCopyObject);  
  51.     }  
  52.     else  
  53.     {  
  54.         pCopy = new CCEaseSineInOut();  
  55.         pNewZone = new CCZone(pCopy);  
  56.     }  
  57.   
  58.     pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()));  
  59.       
  60.     CC_SAFE_DELETE(pNewZone);  
  61.     return pCopy;  
  62. }  
  63. //更新函数。  
  64. void CCEaseSineInOut::update(float time)  
  65. {  
  66.   //上曲线说明:  
  67.     m_pOther->update(-0.5f * (cosf((float)M_PI * time) - 1));  
  68. }  
  69.   
  70. //创建一个反向播放的当前动画。  
  71. CCActionInterval* CCEaseSineInOut::reverse()  
  72. {  
  73.     return CCEaseSineInOut::create(m_pOther->reverse());  
  74. }  



  1. //一个基类,用于衍生后面的变速动画。  
  2. class CC_DLL CCEaseElastic : public CCActionEase  
  3. {  
  4. public:  
  5.     //取得系数  
  6.     inline float getPeriod(void) { return m_fPeriod; }  
  7.    //设置系数  
  8.     inline void setPeriod(float fPeriod) { m_fPeriod = fPeriod; }  
  9.   
  10.     //初始化函数。  
  11.     bool initWithAction(CCActionInterval *pAction, float fPeriod = 0.3f);  
  12.   //创建一个反向播放的当前动画。  
  13.    virtual CCActionInterval* reverse(void);  
  14.      
  15.   //创建一个当前动画的实例拷贝。  
  16.     virtual CCObject* copyWithZone(CCZone* pZone);  
  17.   
  18. public:  
  19.     //静态函数:创建对应匀速动画的变速动画,参数一为一个匀速动画。参数二为系数。内部调用create实现。  
  20.     CC_DEPRECATED_ATTRIBUTE static CCEaseElastic* actionWithAction(CCActionInterval *pAction, float fPeriod = 0.3f);  
  21.     //同上  
  22.     static CCEaseElastic* create(CCActionInterval *pAction, float fPeriod = 0.3f);  
  23. protected:  
  24.    //曲线系数。  
  25.     float m_fPeriod;  
  26. };  
  27.   
  28. //静态函数:创建对应匀速动画的变速动画,参数一为一个匀速动画。参数二为系数。内部调用create实现。  
  29. CCEaseElastic* CCEaseElastic::actionWithAction(CCActionInterval *pAction, float fPeriod/* = 0.3f*/)  
  30. {  
  31.     return CCEaseElastic::create(pAction, fPeriod);  
  32. }  
  33.  //同上  
  34. CCEaseElastic* CCEaseElastic::create(CCActionInterval *pAction, float fPeriod/* = 0.3f*/)  
  35. {  
  36.     CCEaseElastic *pRet = new CCEaseElastic();  
  37.     if (pRet)  
  38.     {  
  39.         if (pRet->initWithAction(pAction, fPeriod))  
  40.         {  
  41.             pRet->autorelease();  
  42.         }  
  43.         else  
  44.         {  
  45.             CC_SAFE_RELEASE_NULL(pRet);  
  46.         }  
  47.     }  
  48.   
  49.     return pRet;   
  50. }  
  51. //初始化函数。  
  52. bool CCEaseElastic::initWithAction(CCActionInterval *pAction, float fPeriod/* = 0.3f*/)  
  53. {  
  54.     if (CCActionEase::initWithAction(pAction))  
  55.    {  
  56.      //保存曲线系数。  
  57.         m_fPeriod = fPeriod;  
  58.         return true;  
  59.     }  
  60.   
  61.     return false;  
  62. }  
  63.     
  64. //创建一个当前动画的实例拷贝。  
  65. CCObject* CCEaseElastic::copyWithZone(CCZone *pZone)  
  66. {  
  67.     CCZone* pNewZone = NULL;  
  68.     CCEaseElastic* pCopy = NULL;  
  69.     if(pZone && pZone->m_pCopyObject)   
  70.     {  
  71.         //in case of being called at sub class  
  72.         pCopy = (CCEaseElastic*)(pZone->m_pCopyObject);  
  73.     }  
  74.     else  
  75.     {  
  76.         pCopy = new CCEaseElastic();  
  77.         pNewZone = new CCZone(pCopy);  
  78.     }  
  79.   
  80.     pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()), m_fPeriod);  
  81.   
  82.     CC_SAFE_DELETE(pNewZone);  
  83.     return pCopy;  
  84. }  
  85. //创建一个反向播放的当前动画。  
  86. CCActionInterval* CCEaseElastic::reverse(void)  
  87. {  
  88.     CCAssert(0, "Override me");  
  89.   
  90.     return NULL;  
  91. }  

  1. //上面基类衍生的新类。  
  2. class CC_DLL CCEaseElasticIn : public CCEaseElastic  
  3. {  
  4. public:  
  5.     //更新动画。  
  6.    virtual void update(float time);  
  7.    //创建一个反向播放的当前动画。  
  8.    virtual CCActionInterval* reverse(void);  
  9.    //创建一个当前动画的实例拷贝。  
  10.     virtual CCObject* copyWithZone(CCZone* pZone);  
  11.   
  12. public:  
  13.    //静态函数:创建对应匀速动画的变速动画,第一参数为一个匀速动画。第二参数为曲线系数,内部调用create实现。  
  14.     CC_DEPRECATED_ATTRIBUTE static CCEaseElasticIn* actionWithAction(CCActionInterval *pAction, float fPeriod = 0.3f);  
  15.     //同上。  
  16.     static CCEaseElasticIn* create(CCActionInterval *pAction, float fPeriod = 0.3f);  
  17. };  
  18.   
  19. //静态函数:创建对应匀速动画的变速动画,第一参数为一个匀速动画。第二参数为曲线系数,内部调用create实现。  
  20. CCEaseElasticIn* CCEaseElasticIn::actionWithAction(CCActionInterval *pAction, float fPeriod/* = 0.3f*/)  
  21. {  
  22.     return CCEaseElasticIn::create(pAction, fPeriod);  
  23. }  
  24.  //同上。  
  25. CCEaseElasticIn* CCEaseElasticIn::create(CCActionInterval *pAction, float fPeriod/* = 0.3f*/)  
  26. {  
  27.     CCEaseElasticIn *pRet = new CCEaseElasticIn();  
  28.     if (pRet)  
  29.     {  
  30.         if (pRet->initWithAction(pAction, fPeriod))  
  31.         {  
  32.             pRet->autorelease();  
  33.         }  
  34.         else  
  35.         {  
  36.             CC_SAFE_RELEASE_NULL(pRet);  
  37.         }  
  38.     }  
  39.   
  40.     return pRet;   
  41. }  
  42. //创建一个当前动画的实例拷贝。  
  43. CCObject* CCEaseElasticIn::copyWithZone(CCZone *pZone)  
  44. {  
  45.     CCZone* pNewZone = NULL;  
  46.     CCEaseElasticIn* pCopy = NULL;  
  47.     if(pZone && pZone->m_pCopyObject)   
  48.     {  
  49.         //in case of being called at sub class  
  50.         pCopy = (CCEaseElasticIn*)(pZone->m_pCopyObject);  
  51.     }  
  52.     else  
  53.     {  
  54.         pCopy = new CCEaseElasticIn();  
  55.         pNewZone = new CCZone(pCopy);  
  56.     }  
  57.   
  58.     pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()), m_fPeriod);  
  59.   
  60.     CC_SAFE_DELETE(pNewZone);  
  61.     return pCopy;  
  62. }  
  63. //更新动画。  
  64. void CCEaseElasticIn::update(float time)  
  65. {  
  66.   //比较复杂,上图说明在不同的系数时的曲线结果:  
  67.     
  68.     float newT = 0;  
  69.     if (time == 0 || time == 1)  
  70.     {  
  71.         newT = time;  
  72.     }  
  73.     else  
  74.     {  
  75.         float s = m_fPeriod / 4;  
  76.         time = time - 1;  
  77.         newT = -powf(2, 10 * time) * sinf((time - s) * M_PI_X_2 / m_fPeriod);  
  78.     }  
  79.   
  80.     m_pOther->update(newT);  
  81. }  
  82. //创建一个反向播放的当前动画。  
  83. CCActionInterval* CCEaseElasticIn::reverse(void)  
  84. {  
  85.     return CCEaseElasticOut::create(m_pOther->reverse(), m_fPeriod);  
  86. }  



  1. class CC_DLL CCEaseElasticOut : public CCEaseElastic  
  2. {  
  3. public:  
  4.     //更新动画。  
  5.    virtual void update(float time);  
  6.    //创建一个反向播放的当前动画。  
  7.    virtual CCActionInterval* reverse(void);  
  8.    //创建一个当前动画的实例拷贝。  
  9.     virtual CCObject* copyWithZone(CCZone* pZone);  
  10.   
  11. public:  
  12.    //静态函数:创建对应匀速动画的变速动画,第一参数为一个匀速动画。第二参数为曲线系数,内部调用create实现。  
  13.     CC_DEPRECATED_ATTRIBUTE static CCEaseElasticOut* actionWithAction(CCActionInterval *pAction, float fPeriod = 0.3f);  
  14.   
  15.     //同上  
  16.     static CCEaseElasticOut* create(CCActionInterval *pAction, float fPeriod = 0.3f);  
  17. };  
  18.    //静态函数:创建对应匀速动画的变速动画,第一参数为一个匀速动画。第二参数为曲线系数,内部调用create实现。  
  19.   
  20. CCEaseElasticOut* CCEaseElasticOut::actionWithAction(CCActionInterval *pAction, float fPeriod/* = 0.3f*/)  
  21. {  
  22.     return CCEaseElasticOut::create(pAction, fPeriod);  
  23. }  
  24. //同上  
  25. CCEaseElasticOut* CCEaseElasticOut::create(CCActionInterval *pAction, float fPeriod/* = 0.3f*/)  
  26. {  
  27.     CCEaseElasticOut *pRet = new CCEaseElasticOut();  
  28.     if (pRet)  
  29.     {  
  30.         if (pRet->initWithAction(pAction, fPeriod))  
  31.         {  
  32.             pRet->autorelease();  
  33.         }  
  34.         else  
  35.         {  
  36.             CC_SAFE_RELEASE_NULL(pRet);  
  37.         }  
  38.     }  
  39.   
  40.     return pRet;   
  41. }  
  42. //创建一个当前动画的实例拷贝。  
  43. CCObject *CCEaseElasticOut::copyWithZone(CCZone *pZone)  
  44. {  
  45.     CCZone* pNewZone = NULL;  
  46.     CCEaseElasticOut* pCopy = NULL;  
  47.     if(pZone && pZone->m_pCopyObject)   
  48.     {  
  49.         //in case of being called at sub class  
  50.         pCopy = (CCEaseElasticOut*)(pZone->m_pCopyObject);  
  51.     }  
  52.     else  
  53.     {  
  54.         pCopy = new CCEaseElasticOut();  
  55.         pNewZone = new CCZone(pCopy);  
  56.     }  
  57.   
  58.     pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()), m_fPeriod);  
  59.   
  60.     CC_SAFE_DELETE(pNewZone);  
  61.     return pCopy;  
  62. }  
  63. //更新动画。  
  64. void CCEaseElasticOut::update(float time)  
  65. {  
  66.   //继续上曲线说明:  
  67.     
  68.     float newT = 0;  
  69.     if (time == 0 || time == 1)  
  70.     {  
  71.         newT = time;  
  72.     }  
  73.     else  
  74.     {  
  75.         float s = m_fPeriod / 4;  
  76.         newT = powf(2, -10 * time) * sinf((time - s) * M_PI_X_2 / m_fPeriod)   1;  
  77.     }  
  78.   
  79.     m_pOther->update(newT);  
  80. }  
  81. //创建一个反向播放的当前动画。  
  82. CCActionInterval* CCEaseElasticOut::reverse(void)  
  83. {  
  84.     return CCEaseElasticIn::create(m_pOther->reverse(), m_fPeriod);  
  85. }  




  1. class CC_DLL CCEaseElasticInOut : public CCEaseElastic  
  2. {  
  3. public:  
  4.     //更新动画。  
  5.    virtual void update(float time);  
  6.    //创建一个反向播放的当前动画。  
  7.    virtual CCActionInterval* reverse(void);  
  8.    //创建一个当前动画的实例拷贝。  
  9.     virtual CCObject* copyWithZone(CCZone* pZone);  
  10.   
  11. public:  
  12.    //静态函数:创建对应匀速动画的变速动画,第一参数为一个匀速动画。第二参数为曲线系数,内部调用create实现。  
  13.     CC_DEPRECATED_ATTRIBUTE static CCEaseElasticInOut* actionWithAction(CCActionInterval *pAction, float fPeriod = 0.3f);  
  14.   
  15.     //同上  
  16.     static CCEaseElasticInOut* create(CCActionInterval *pAction, float fPeriod = 0.3f);  
  17. };  
  18. //静态函数:创建对应匀速动画的变速动画,第一参数为一个匀速动画。第二参数为曲线系数,内部调用create实现。  
  19. CCEaseElasticInOut* CCEaseElasticInOut::actionWithAction(CCActionInterval *pAction, float fPeriod/* = 0.3f*/)  
  20. {  
  21.     return CCEaseElasticInOut::create(pAction, fPeriod);  
  22. }  
  23. //同上  
  24. CCEaseElasticInOut* CCEaseElasticInOut::create(CCActionInterval *pAction, float fPeriod/* = 0.3f*/)  
  25. {  
  26.     CCEaseElasticInOut *pRet = new CCEaseElasticInOut();  
  27.     if (pRet)  
  28.     {  
  29.         if (pRet->initWithAction(pAction, fPeriod))  
  30.         {  
  31.             pRet->autorelease();  
  32.         }  
  33.         else  
  34.         {  
  35.             CC_SAFE_RELEASE_NULL(pRet);  
  36.         }  
  37.     }  
  38.   
  39.     return pRet;   
  40. }  
  41. //创建一个当前动画的实例拷贝。  
  42. CCObject* CCEaseElasticInOut::copyWithZone(CCZone *pZone)  
  43. {  
  44.     CCZone* pNewZone = NULL;  
  45.     CCEaseElasticInOut* pCopy = NULL;  
  46.     if(pZone && pZone->m_pCopyObject)   
  47.     {  
  48.         //in case of being called at sub class  
  49.         pCopy = (CCEaseElasticInOut*)(pZone->m_pCopyObject);  
  50.     }  
  51.     else  
  52.     {  
  53.         pCopy = new CCEaseElasticInOut();  
  54.         pNewZone = new CCZone(pCopy);  
  55.     }  
  56.   
  57.     pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()), m_fPeriod);  
  58.   
  59.     CC_SAFE_DELETE(pNewZone);  
  60.     return pCopy;  
  61.   
  62. }  
  63. //更新动画。  
  64. void CCEaseElasticInOut::update(float time)  
  65. {  
  66.   //挺复杂的曲线:  
  67.     
  68.     float newT = 0;  
  69.     if (time == 0 || time == 1)  
  70.     {  
  71.         newT = time;  
  72.     }  
  73.     else  
  74.     {  
  75.         time = time * 2;  
  76.         if (! m_fPeriod)  
  77.         {  
  78.             m_fPeriod = 0.3f * 1.5f;  
  79.         }  
  80.   
  81.         float s = m_fPeriod / 4;  
  82.   
  83.         time = time - 1;  
  84.         if (time < 0)  
  85.         {  
  86.             newT = -0.5f * powf(2, 10 * time) * sinf((time -s) * M_PI_X_2 / m_fPeriod);  
  87.         }  
  88.         else  
  89.         {  
  90.             newT = powf(2, -10 * time) * sinf((time - s) * M_PI_X_2 / m_fPeriod) * 0.5f   1;  
  91.         }  
  92.     }  
  93.   
  94.     m_pOther->update(newT);  
  95. }  
  96. //创建一个反向播放的当前动画。  
  97. CCActionInterval* CCEaseElasticInOut::reverse(void)  
  98. {  
  99.     return CCEaseElasticInOut::create(m_pOther->reverse(), m_fPeriod);  
  100. }  


  1. //又是一个变速动画的基类,用于衍生一些复杂的变速曲线。  
  2. class CC_DLL CCEaseBounce : public CCActionEase  
  3. {  
  4. public:  
  5.   //计算曲线处理  
  6.    float bounceTime(float time);  
  7.    //产生一个当前类的实例拷贝。  
  8.    virtual CCObject* copyWithZone(CCZone* pZone);  
  9.    //创建一个反向播放的当前动画  
  10.     virtual CCActionInterval* reverse();  
  11.   
  12. public:  
  13.    //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  14.     CC_DEPRECATED_ATTRIBUTE static CCEaseBounce* actionWithAction(CCActionInterval* pAction);  
  15.     //同上。  
  16.     static CCEaseBounce* create(CCActionInterval* pAction);  
  17. };  
  18.      
  19. //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  20. CCEaseBounce* CCEaseBounce::actionWithAction(CCActionInterval* pAction)  
  21. {  
  22.     return CCEaseBounce::create(pAction);  
  23. }  
  24. //同上。  
  25. CCEaseBounce* CCEaseBounce::create(CCActionInterval* pAction)  
  26. {  
  27.     CCEaseBounce *pRet = new CCEaseBounce();  
  28.     if (pRet)  
  29.     {  
  30.         if (pRet->initWithAction(pAction))  
  31.         {  
  32.             pRet->autorelease();  
  33.         }  
  34.         else  
  35.         {  
  36.             CC_SAFE_RELEASE_NULL(pRet);  
  37.         }  
  38.     }  
  39.   
  40.     return pRet;   
  41. }  
  42. //产生一个当前类的实例拷贝。  
  43. CCObject* CCEaseBounce::copyWithZone(CCZone *pZone)  
  44. {  
  45.     CCZone* pNewZone = NULL;  
  46.     CCEaseBounce* pCopy = NULL;  
  47.     if(pZone && pZone->m_pCopyObject)   
  48.     {  
  49.         //in case of being called at sub class  
  50.         pCopy = (CCEaseBounce*)(pZone->m_pCopyObject);  
  51.     }  
  52.     else  
  53.     {  
  54.         pCopy = new CCEaseBounce();  
  55.         pNewZone = new CCZone(pCopy);  
  56.     }  
  57.   
  58.     pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()));  
  59.       
  60.     CC_SAFE_DELETE(pNewZone);  
  61.     return pCopy;  
  62. }  
  63. //计算曲线处理  
  64. float CCEaseBounce::bounceTime(float time)  
  65. {  
  66.   //复杂曲线说明:  
  67.     
  68.     if (time < 1 / 2.75)  
  69.     {  
  70.         return 7.5625f * time * time;  
  71.     } else   
  72.     if (time < 2 / 2.75)  
  73.     {  
  74.         time -= 1.5f / 2.75f;  
  75.         return 7.5625f * time * time   0.75f;  
  76.     } else  
  77.     if(time < 2.5 / 2.75)  
  78.     {  
  79.         time -= 2.25f / 2.75f;  
  80.         return 7.5625f * time * time   0.9375f;  
  81.     }  
  82.   
  83.     time -= 2.625f / 2.75f;  
  84.     return 7.5625f * time * time   0.984375f;  
  85. }  
  86. //创建一个反向播放的当前动画  
  87. CCActionInterval* CCEaseBounce::reverse()  
  88. {  
  89.     return CCEaseBounce::create(m_pOther->reverse());  
  90. }  


  1. //上面类的衍生类。  
  2. class CC_DLL CCEaseBounceIn : public CCEaseBounce  
  3. {  
  4. public:  
  5.     //更新动画。  
  6.    virtual void update(float time);  
  7.    //创建一个反向播放的当前动画。  
  8.    virtual CCActionInterval* reverse(void);  
  9.    //创建一个当前动画的实例拷贝。  
  10.     virtual CCObject* copyWithZone(CCZone* pZone);  
  11.   
  12. public:  
  13.    //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  14.     CC_DEPRECATED_ATTRIBUTE static CCEaseBounceIn* actionWithAction(CCActionInterval* pAction);  
  15.     //同上。  
  16.     static CCEaseBounceIn* create(CCActionInterval* pAction);  
  17. };  
  18. //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  19. CCEaseBounceIn* CCEaseBounceIn::actionWithAction(CCActionInterval* pAction)  
  20. {  
  21.     return CCEaseBounceIn::create(pAction);  
  22. }  
  23. //同上。  
  24. CCEaseBounceIn* CCEaseBounceIn::create(CCActionInterval* pAction)  
  25. {  
  26.     CCEaseBounceIn *pRet = new CCEaseBounceIn();  
  27.     if (pRet)  
  28.     {  
  29.         if (pRet->initWithAction(pAction))  
  30.         {  
  31.             pRet->autorelease();  
  32.         }  
  33.         else  
  34.         {  
  35.             CC_SAFE_RELEASE_NULL(pRet);  
  36.         }  
  37.     }  
  38.   
  39.     return pRet;   
  40. }  
  41. //创建一个当前动画的实例拷贝。  
  42. CCObject* CCEaseBounceIn::copyWithZone(CCZone *pZone)  
  43. {  
  44.     CCZone* pNewZone = NULL;  
  45.     CCEaseBounceIn* pCopy = NULL;  
  46.     if(pZone && pZone->m_pCopyObject)   
  47.     {  
  48.         //in case of being called at sub class  
  49.         pCopy = (CCEaseBounceIn*)(pZone->m_pCopyObject);  
  50.     }  
  51.     else  
  52.     {  
  53.         pCopy = new CCEaseBounceIn();  
  54.         pNewZone = new CCZone(pCopy);  
  55.     }  
  56.   
  57.     pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()));  
  58.       
  59.     CC_SAFE_DELETE(pNewZone);  
  60.     return pCopy;  
  61. }  
  62. //更新动画。  
  63. void CCEaseBounceIn::update(float time)  
  64. {  
  65.   //先计算出变速曲线的结果然后做为进度值设置给匀速动画。  
  66.   //曲线未设系数,为固定曲线。  
  67.     
  68.     float newT = 1 - bounceTime(1 - time);  
  69.     m_pOther->update(newT);  
  70. }  
  71. //创建一个反向播放的当前动画。  
  72. CCActionInterval* CCEaseBounceIn::reverse(void)  
  73. {  
  74.     return CCEaseBounceOut::create(m_pOther->reverse());  
  75. }  




  1. class CC_DLL CCEaseBounceOut : public CCEaseBounce  
  2. {  
  3. public:  
  4.     //更新动画。  
  5.    virtual void update(float time);  
  6.    //创建一个反向播放的当前动画。  
  7.    virtual CCActionInterval* reverse(void);  
  8.    //创建一个当前动画的实例拷贝。  
  9.     virtual CCObject* copyWithZone(CCZone* pZone);  
  10.   
  11. public:  
  12.    //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  13.     CC_DEPRECATED_ATTRIBUTE static CCEaseBounceOut* actionWithAction(CCActionInterval* pAction);  
  14.     //同上  
  15.     static CCEaseBounceOut* create(CCActionInterval* pAction);  
  16. };  
  17. //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  18. CCEaseBounceOut* CCEaseBounceOut::actionWithAction(CCActionInterval* pAction)  
  19. {  
  20.     return CCEaseBounceOut::create(pAction);  
  21. }  
  22. //同上  
  23. CCEaseBounceOut* CCEaseBounceOut::create(CCActionInterval* pAction)  
  24. {  
  25.     CCEaseBounceOut *pRet = new CCEaseBounceOut();  
  26.     if (pRet)  
  27.     {  
  28.         if (pRet->initWithAction(pAction))  
  29.         {  
  30.             pRet->autorelease();  
  31.         }  
  32.         else  
  33.         {  
  34.             CC_SAFE_RELEASE_NULL(pRet);  
  35.         }  
  36.     }  
  37.   
  38.     return pRet;   
  39. }  
  40. //创建一个当前动画的实例拷贝。  
  41. CCObject* CCEaseBounceOut::copyWithZone(CCZone *pZone)  
  42. {  
  43.     CCZone* pNewZone = NULL;  
  44.     CCEaseBounceOut* pCopy = NULL;  
  45.     if(pZone && pZone->m_pCopyObject)  
  46.     {  
  47.         //in case of being called at sub class  
  48.         pCopy = (CCEaseBounceOut*)(pZone->m_pCopyObject);  
  49.     }  
  50.     else  
  51.     {  
  52.         pCopy = new CCEaseBounceOut();  
  53.         pNewZone = new CCZone(pCopy);  
  54.     }  
  55.   
  56.     pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()));  
  57.       
  58.     CC_SAFE_DELETE(pNewZone);  
  59.     return pCopy;  
  60. }  
  61. //更新动画  
  62. void CCEaseBounceOut::update(float time)  
  63. {  
  64.   //曲线说明:  
  65.   //曲线未设系数,为固定曲线。  
  66.     
  67.     float newT = bounceTime(time);  
  68.     m_pOther->update(newT);  
  69. }  
  70. //创建一个反向播放的当前动画。  
  71. CCActionInterval* CCEaseBounceOut::reverse(void)  
  72. {  
  73.     return CCEaseBounceIn::create(m_pOther->reverse());  
  74. }  



  1. class CC_DLL CCEaseBounceInOut : public CCEaseBounce  
  2. {  
  3. public:  
  4.     //更新动画。  
  5.    virtual void update(float time);  
  6.    //创建一个反向播放的当前动画。  
  7.    virtual CCActionInterval* reverse(void);  
  8.    //创建一个当前动画的实例拷贝。  
  9.     virtual CCObject* copyWithZone(CCZone* pZone);  
  10.   
  11. public:  
  12.    //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  13.     CC_DEPRECATED_ATTRIBUTE static CCEaseBounceInOut* actionWithAction(CCActionInterval* pAction);  
  14.     //同上  
  15.     static CCEaseBounceInOut* create(CCActionInterval* pAction);  
  16. };  
  17.    //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  18. CCEaseBounceInOut* CCEaseBounceInOut::actionWithAction(CCActionInterval* pAction)  
  19. {  
  20.     return CCEaseBounceInOut::create(pAction);  
  21. }  
  22. //同上  
  23. CCEaseBounceInOut* CCEaseBounceInOut::create(CCActionInterval* pAction)  
  24. {  
  25.     CCEaseBounceInOut *pRet = new CCEaseBounceInOut();  
  26.     if (pRet)  
  27.     {  
  28.         if (pRet->initWithAction(pAction))  
  29.         {  
  30.             pRet->autorelease();  
  31.         }  
  32.         else  
  33.         {  
  34.             CC_SAFE_RELEASE_NULL(pRet);  
  35.         }  
  36.     }  
  37.   
  38.     return pRet;   
  39. }  
  40. //创建一个当前动画的实例拷贝。  
  41. CCObject* CCEaseBounceInOut::copyWithZone(CCZone *pZone)  
  42. {  
  43.     CCZone* pNewZone = NULL;  
  44.     CCEaseBounceInOut* pCopy = NULL;  
  45.     if(pZone && pZone->m_pCopyObject)   
  46.     {  
  47.         //in case of being called at sub class  
  48.         pCopy = (CCEaseBounceInOut*)(pZone->m_pCopyObject);  
  49.     }  
  50.     else  
  51.     {  
  52.         pCopy = new CCEaseBounceInOut();  
  53.         pNewZone = new CCZone(pCopy);  
  54.     }  
  55.   
  56.     pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()));  
  57.       
  58.     CC_SAFE_DELETE(pNewZone);  
  59.     return pCopy;  
  60. }  
  61. //动画更新  
  62. void CCEaseBounceInOut::update(float time)  
  63. {  
  64.   //曲线说明:  
  65.     
  66.     float newT = 0;  
  67.     if (time < 0.5f)  
  68.     {  
  69.         time = time * 2;  
  70.         newT = (1 - bounceTime(1 - time)) * 0.5f;  
  71.     }  
  72.     else  
  73.     {  
  74.         newT = bounceTime(time * 2 - 1) * 0.5f   0.5f;  
  75.     }  
  76.   
  77.     m_pOther->update(newT);  
  78. }  
  79. //创建一个反向播放的当前动画。  
  80.   
  81. CCActionInterval* CCEaseBounceInOut::reverse()  
  82. {  
  83.     return CCEaseBounceInOut::create(m_pOther->reverse());  
  84. }  


  1. class CC_DLL CCEaseBackIn : public CCActionEase  
  2. {  
  3. public:  
  4.     //更新动画。  
  5.    virtual void update(float time);  
  6.    //创建一个反向播放的当前动画。  
  7.    virtual CCActionInterval* reverse(void);  
  8.    //创建一个当前动画的实例拷贝。  
  9.     virtual CCObject* copyWithZone(CCZone* pZone);  
  10.   
  11. public:  
  12.    //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  13.     CC_DEPRECATED_ATTRIBUTE static CCEaseBackIn* actionWithAction(CCActionInterval* pAction);  
  14.     //同上  
  15.     static CCEaseBackIn* create(CCActionInterval* pAction);  
  16. };  
  17. //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  18. CCEaseBackIn* CCEaseBackIn::actionWithAction(CCActionInterval *pAction)  
  19. {  
  20.     return CCEaseBackIn::create(pAction);  
  21. }  
  22. //同上  
  23. CCEaseBackIn* CCEaseBackIn::create(CCActionInterval *pAction)  
  24. {  
  25.     CCEaseBackIn *pRet = new CCEaseBackIn();  
  26.     if (pRet)  
  27.     {  
  28.         if (pRet->initWithAction(pAction))  
  29.         {  
  30.             pRet->autorelease();  
  31.         }  
  32.         else  
  33.         {  
  34.             CC_SAFE_RELEASE_NULL(pRet);  
  35.         }  
  36.     }  
  37.   
  38.     return pRet;  
  39. }  
  40. //创建一个当前动画的实例拷贝。  
  41. CCObject* CCEaseBackIn::copyWithZone(CCZone *pZone)  
  42. {  
  43.     CCZone* pNewZone = NULL;  
  44.     CCEaseBackIn* pCopy = NULL;  
  45.     if(pZone && pZone->m_pCopyObject)   
  46.     {  
  47.         //in case of being called at sub class  
  48.         pCopy = (CCEaseBackIn*)(pZone->m_pCopyObject);  
  49.     }  
  50.     else  
  51.     {  
  52.         pCopy = new CCEaseBackIn();  
  53.         pNewZone = new CCZone(pCopy);  
  54.     }  
  55.   
  56.     pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()));  
  57.       
  58.     CC_SAFE_DELETE(pNewZone);  
  59.     return pCopy;  
  60. }  
  61. //更新动画.  
  62. void CCEaseBackIn::update(float time)  
  63. {  
  64.   //菜花,上曲线!  
  65.     
  66.     float overshoot = 1.70158f;  
  67.     m_pOther->update(time * time * ((overshoot   1) * time - overshoot));  
  68. }  
  69. //创建一个反向播放的当前动画。  
  70. CCActionInterval* CCEaseBackIn::reverse(void)  
  71. {  
  72.     return CCEaseBackOut::create(m_pOther->reverse());  
  73. }  




  1. class CC_DLL CCEaseBackOut : public CCActionEase  
  2. {  
  3. public:  
  4.     //更新动画。  
  5.    virtual void update(float time);  
  6.    //创建一个反向播放的当前动画。  
  7.    virtual CCActionInterval* reverse(void);  
  8.    //创建一个当前动画的实例拷贝。  
  9.     virtual CCObject* copyWithZone(CCZone* pZone);  
  10.   
  11. public:  
  12.    //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  13.     CC_DEPRECATED_ATTRIBUTE static CCEaseBackOut* actionWithAction(CCActionInterval* pAction);  
  14.     //同上  
  15.     static CCEaseBackOut* create(CCActionInterval* pAction);  
  16. };  
  17. //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  18. CCEaseBackOut* CCEaseBackOut::actionWithAction(CCActionInterval* pAction)  
  19. {  
  20.     return CCEaseBackOut::create(pAction);  
  21. }  
  22. //同上  
  23. CCEaseBackOut* CCEaseBackOut::create(CCActionInterval* pAction)  
  24. {  
  25.     CCEaseBackOut *pRet = new CCEaseBackOut();  
  26.     if (pRet)  
  27.     {  
  28.         if (pRet->initWithAction(pAction))  
  29.         {  
  30.             pRet->autorelease();  
  31.         }  
  32.         else  
  33.         {  
  34.             CC_SAFE_RELEASE_NULL(pRet);  
  35.         }  
  36.     }  
  37.   
  38.     return pRet;  
  39. }  
  40. //创建一个当前动画的实例拷贝。  
  41. CCObject* CCEaseBackOut::copyWithZone(CCZone *pZone)  
  42. {  
  43.     CCZone* pNewZone = NULL;  
  44.     CCEaseBackOut* pCopy = NULL;  
  45.     if(pZone && pZone->m_pCopyObject)   
  46.     {  
  47.         //in case of being called at sub class  
  48.         pCopy = (CCEaseBackOut*)(pZone->m_pCopyObject);  
  49.     }  
  50.     else  
  51.     {  
  52.         pCopy = new CCEaseBackOut();  
  53.         pNewZone = new CCZone(pCopy);  
  54.     }  
  55.   
  56.     pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()));  
  57.       
  58.     CC_SAFE_DELETE(pNewZone);  
  59.     return pCopy;  
  60. }  
  61. //更新动画.  
  62. void CCEaseBackOut::update(float time)  
  63. {  
  64.   //奶妈,上曲线!  
  65.     
  66.     float overshoot = 1.70158f;  
  67.   
  68.     time = time - 1;  
  69.     m_pOther->update(time * time * ((overshoot   1) * time   overshoot)   1);  
  70. }  
  71. //创建一个反向播放的当前动画。  
  72. CCActionInterval* CCEaseBackOut::reverse(void)  
  73. {  
  74.     return CCEaseBackIn::create(m_pOther->reverse());  
  75. }  




  1. class CC_DLL CCEaseBackInOut : public CCActionEase  
  2. {  
  3. public:  
  4.     //更新动画。  
  5.    virtual void update(float time);  
  6.    //创建一个反向播放的当前动画。  
  7.    virtual CCActionInterval* reverse(void);  
  8.    //创建一个当前动画的实例拷贝。  
  9.     virtual CCObject* copyWithZone(CCZone* pZone);  
  10.   
  11. public:  
  12.    //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  13.     CC_DEPRECATED_ATTRIBUTE static CCEaseBackInOut* actionWithAction(CCActionInterval* pAction);  
  14.    //同上  
  15.     static CCEaseBackInOut* create(CCActionInterval* pAction);  
  16. };  
  17. //静态函数:创建对应匀速动画的变速动画,参数为一个匀速动画。内部调用create实现。  
  18. CCEaseBackInOut* CCEaseBackInOut::actionWithAction(CCActionInterval* pAction)  
  19. {  
  20.     return CCEaseBackInOut::create(pAction);  
  21. }  
  22. //同上  
  23. CCEaseBackInOut* CCEaseBackInOut::create(CCActionInterval* pAction)  
  24. {  
  25.     CCEaseBackInOut *pRet = new CCEaseBackInOut();  
  26.     if (pRet)  
  27.     {  
  28.         if (pRet->initWithAction(pAction))  
  29.         {  
  30.             pRet->autorelease();  
  31.         }  
  32.         else  
  33.         {  
  34.             CC_SAFE_RELEASE_NULL(pRet);  
  35.         }  
  36.     }  
  37.   
  38.     return pRet;  
  39. }  
  40. //创建一个当前动画的实例拷贝。  
  41. CCObject* CCEaseBackInOut::copyWithZone(CCZone *pZone)  
  42. {  
  43.     CCZone* pNewZone = NULL;  
  44.     CCEaseBackInOut* pCopy = NULL;  
  45.     if(pZone && pZone->m_pCopyObject)   
  46.     {  
  47.         //in case of being called at sub class  
  48.         pCopy = (CCEaseBackInOut*)(pZone->m_pCopyObject);  
  49.     }  
  50.     else  
  51.     {  
  52.         pCopy = new CCEaseBackInOut();  
  53.         pNewZone = new CCZone(pCopy);  
  54.     }  
  55.   
  56.     pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()));  
  57.       
  58.     CC_SAFE_DELETE(pNewZone);  
  59.     return pCopy;  
  60. }  
  61. //动画更新  
  62. void CCEaseBackInOut::update(float time)  
  63. {  
  64.   //容嬷嬷,上曲线!  
  65.     
  66.     float overshoot = 1.70158f * 1.525f;  
  67.   
  68.     time = time * 2;  
  69.     if (time < 1)  
  70.     {  
  71.         m_pOther->update((time * time * ((overshoot   1) * time - overshoot)) / 2);  
  72.     }  
  73.     else  
  74.     {  
  75.         time = time - 2;  
  76.         m_pOther->update((time * time * ((overshoot   1) * time   overshoot)) / 2   1);  
  77.     }  
  78. }  
  79.   
  80. //创建一个反向播放的当前动画。  
  81. CCActionInterval* CCEaseBackInOut::reverse()  
  82. {  
  83.     return CCEaseBackInOut::create(m_pOther->reverse());  
  84. }  

如社区发表内容存在侵权行为,您可以点击这里查看侵权投诉指引

标签: