cocos2d-x動畫加速與減速(轉載) 轉

最近的遊戲學習中使用到精靈運動的加速與減速,於是徵集了一些權威的文章供參考。

文章一:

cocos2d-x動畫加速與減速

動畫是遊戲的必然要素之一,在整個遊戲過程中,又有着加速、減速動畫的需求。以塔防爲例子,布塔的時候希望能夠將遊戲減速,布好塔後,則希 望能將遊戲加速;當某個怪被冰凍後,移動速度減緩,而其他怪的移動速度不變。cocos2d-x引擎爲我們提供了很強大的接口,下面就將我實驗的過程複述 一遍,也方便他人。

1)實現全局的加速、減速。

通過設置Scheduler的timeScale,可以實現全局的加、減速。代碼非常簡單:
CCScheduler* pScheduler = CCDirector::sharedDirector()->getScheduler();
pScheduler->setTimeScale(2.0f); //實現加速效果
pScheduler->setTimeScale(0.5f);//實現減速效果

 

2)實現對某個CCActionInterval動作的加速、減速

方法一:很容易想到的一個方法就是改變CCAnimation的delay unit。代碼如下:

CCAnimation* pAnimation = CCAnimationCache::sharedAnimationCache()->animationByName(“xxx”);

pAnimation->setDelayUnit(pAnimation->getDelayUnit()*0.2f); //速度爲原來的5倍

這個方法有一個缺點:改變了CCAnimationCache中這個animation的delay unit。也就是說以後即使再從CCAnimationCache中獲取這個animation,其delay unit已經是原來的0.2倍了。

 

方法二:cocos2d-x提供了CCSpeed的類,可以實現動畫速度的調節。用法如下:

CCActionInterval* pActionInterval = CCMoveTo::create(5.0f, ccp(500.0f, 100.0f));

CCSpeed* pSpeed= CCSpeed::create(pActionInterval, 1.5f); //1.5倍速運行

CCSpeed* pSpeed1 = CCSpeed::create(pActionInterval, 0.2f);// 0.2倍速運行

pSprite->runAction(pSpeed);

注意,如果pSprite有已經運行的動作,要用pSprite->stopActionByTag()停掉之前的動作,不然兩個動作就疊加到一起了。

—————————————————————–華麗麗的分割線————————————————————————–

來自HIMI的提示:

很多時候你的主角的動作利用CCAction來實現,移動則是在update刷幀函 數或者一些選擇器的方法中進行的,那麼爲了讓你的主角慢動作比較逼真,那麼Himi建議不要使用scheduleUpdate函數,因爲這個你無法修改每 次調用update的時間默認都是每幀都調用,那麼你應該自己定義一個選擇器當刷邏輯的函數,這樣就能配合CCSpeed實現逼真慢動作拉~

3)對某個CCFiniteTimeAction類型動作的加速、減速

大部分時候,一個遊戲人物的動作並非由單一一個CCActionInterval類型的動作構成,而是一串動作連起來,構成一個Sequence。 用CCSequence::create(…)創建的對象都是CCFinteTimeAction類型的,CCSpeed並不適用。在CCSpeed類的 說明裏,明確指 出”This action can’t be Sequenceable because it is not an CCIntervalAction”。 那對於Sequence就束手無策了嗎?非也。cocos2d-x引擎自帶例子中,schedulerTest給我們展示瞭如何控制某個sprite的 scheduler的timescale。廢話少說,直接看代碼。

在class TwoSchedulers中定義了兩個customer的scheduler和兩個CCActionManager。
CCScheduler *sched1;
CCScheduler *sched2;
CCActionManager *actionManager1;
CCActionManager *actionManager2;

在onEnter函數中,分別對兩個sprite設置customer的ActionManager.
CCScheduler *defaultScheduler = CCDirector::sharedDirector()->getScheduler();
// Create a new scheduler, and link it to the main scheduler
sched1 = new CCScheduler();
defaultScheduler->scheduleUpdateForTarget(sched1, 0, false);
// Create a new ActionManager, and link it to the new scheudler
actionManager1 = new CCActionManager();
sched1->scheduleUpdateForTarget(actionManager1, 0, false);
// Replace the default ActionManager with the new one.
pSprite1->setActionManager(actionManager1);

通過以上的代碼,就可以通過改變sched1的timescale來改變pSprite1的動作的快慢了。有了這種方法,那麼就可以放棄CCSpeed的那種方法了。

文章二:

在實現運動中,我們常常需要實現一些加速度或者減速度的效果,cocos2d-x引擎爲我們提供了相應的實現接口,這樣我們就不用再用原來的公式計算方法來實現加減速度的效果

Ease系列的方法改變了運動的速度,但是並沒有改變總體時間,如果整個的action持續5秒鐘,那麼整個的時間仍然會持續5秒鐘。

這些action可以被分成3類:

In actions: action開始的時候加速

Out actions: action結束的時候加速

InOut actions: action開始,結束的時候加速

第一個參數爲要加減速度的動作,第二個爲加減的速率

還有一些特殊的緩衝公式繼承了進來

1.指數緩衝

 

EaseExponentialIn

EaseExponentialOut

EaseExponentialInOut

2.賽因緩衝

 

EaseSineIn

EaseSineOut

EaseSineInOut

 

3.彈性緩衝


 

 

EaseElasticIn

EaseElasticOut

EaseElasticInOut

4.跳躍緩衝

 

EaseBounceIn

EaseBounceOut

EaseBounceInOut

5.回震緩衝

 

EaseBackIn

EaseBackOut

EaseBackInOut

另外還可以設置速度的倍數

通過把動作定義爲CCSpeed並改變速度,使用setSpeed將速度按參數的倍數變大或者縮小,這樣可以手動實現加減速度


文章三:移動開發:Cocos2d-x 2.0變速動畫深入分析

變 速動畫都是由時間動畫所衍生出來的,它是通過對一個勻速動畫的進度進行調節來實現的,所以你要運行一個變速動畫,首先要給他指定一個勻速動畫,播放這個變 速動畫,它也播放被指定的勻速動畫,在變速動畫的更新函數中對被指定的勻速動畫通過一個變速曲線計算得到相應的播放進度,變速動畫停止播放時,被指定的勻 速動畫也必須被停止。所以,變速動畫其實就是一個控制器,用來控制一個勻速動畫的播放進度,使其產生變速的效果。

 

      爲了講述好本節,我專門寫了一個曲線生成工具,這樣可以更直觀的看到變速曲線的形態。有興趣的可以到我的羣裏下載這個工具。

 

      打開CActionEase.h:

 

 

[cpp] view plaincopy

  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:

 

 

[cpp] view plaincopy

  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. }  

 

 

       上面只是一個基類,它並未真正的提供速度的變化調節,下面還有一個基類,提供了一個速度調節係數值。

 

[cpp] view plaincopy

  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實現:

 

 

[cpp] view plaincopy

  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. }  

 

 

       第二個類有了速度屬性,但這個速度屬性並未對動畫起任何作用。後面的類由這個帶速度屬性的動畫基類派生,真正實現相應的變速效果。


[cpp] view plaincopy

  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:

 

 

[cpp] view plaincopy

  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. }  

 

 

 

[cpp] view plaincopy

  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:

 

 

[cpp] view plaincopy

  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. }  

 

 

 

[cpp] view plaincopy

  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. }  

 

 

 

[cpp] view plaincopy

  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. }  


 

 

 

 

 

 

[cpp] view plaincopy

  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. }  


 

 

 

 

 

 

[cpp] view plaincopy

  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. }  


 

 

 

 

 

[cpp] view plaincopy

  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. }  


 

 

 

 

 

 

[cpp] view plaincopy

  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. }  


 

 

 

 

 

 

[cpp] view plaincopy

  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. }  


 

 

 

 

 

 

[cpp] view plaincopy

  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. }  


[cpp] view plaincopy

  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. }  

 

 

 

 

 

[cpp] view plaincopy

  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. }  


 

 

 

 

 

 

[cpp] view plaincopy

  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. }  


 

 

 

 

 

[cpp] view plaincopy

  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. }  

 

 

 

 

 

 

[cpp] view plaincopy

  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. }  


 

 

 

 

 

 

[cpp] view plaincopy

  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. }  

 

 

 

 

 

 

[cpp] view plaincopy

  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. }  

 

 

 

 

 

 

[cpp] view plaincopy

  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. }  




[cpp] view plaincopy

  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. }  


 

 

 

 

 

 

[cpp] view plaincopy

  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. }  


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章