最近的游戏学习中使用到精灵运动的加速与减速,于是征集了一些权威的文章供参考。
文章一:
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 plain copy
- #ifndef __ACTION_CCEASE_ACTION_H__
- #define __ACTION_CCEASE_ACTION_H__
-
- #include "CCActionInterval.h"
-
- NS_CC_BEGIN
-
- class CCObject;
- class CCZone;
-
-
- class CC_DLL CCActionEase : public CCActionInterval
- {
- public:
-
- virtual ~CCActionEase(void);
-
-
- bool initWithAction(CCActionInterval *pAction);
-
- virtual CCObject* copyWithZone(CCZone* pZone);
-
- virtual void startWithTarget(CCNode *pTarget);
-
- virtual void stop(void);
-
- virtual void update(float time);
-
- virtual CCActionInterval* reverse(void);
-
- public:
-
- CC_DEPRECATED_ATTRIBUTE static CCActionEase* actionWithAction(CCActionInterval *pAction);
-
-
- static CCActionEase* create(CCActionInterval *pAction);
-
- protected:
-
- CCActionInterval *m_pOther;
- };
对应CPP:
[cpp]
view plain copy
-
- CCActionEase* CCActionEase::actionWithAction(CCActionInterval *pAction)
- {
- return CCActionEase::create(pAction);
- }
-
- CCActionEase* CCActionEase::create(CCActionInterval *pAction)
- {
-
- CCActionEase *pRet = new CCActionEase();
- if (pRet)
- {
-
- if (pRet->initWithAction(pAction))
- {
-
- pRet->autorelease();
- }
- else
- {
-
- CC_SAFE_RELEASE_NULL(pRet);
- }
- }
-
- return pRet;
- }
-
- bool CCActionEase::initWithAction(CCActionInterval *pAction)
- {
-
- CCAssert(pAction != NULL, "");
-
- if (CCActionInterval::initWithDuration(pAction->getDuration()))
- {
-
- m_pOther = pAction;
- pAction->retain();
-
- return true;
- }
-
- return false;
- }
-
- CCObject* CCActionEase::copyWithZone(CCZone *pZone)
- {
-
- CCZone* pNewZone = NULL;
- CCActionEase* pCopy = NULL;
-
- if(pZone && pZone->m_pCopyObject)
- {
-
- pCopy = (CCActionEase*)(pZone->m_pCopyObject);
- }
- else
- {
-
- pCopy = new CCActionEase();
- pZone = pNewZone = new CCZone(pCopy);
- }
-
- CCActionInterval::copyWithZone(pZone);
-
- pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()));
-
- CC_SAFE_DELETE(pNewZone);
- return pCopy;
- }
-
- CCActionEase::~CCActionEase(void)
- {
-
- CC_SAFE_RELEASE(m_pOther);
- }
-
-
- void CCActionEase::startWithTarget(CCNode *pTarget)
- {
-
- CCActionInterval::startWithTarget(pTarget);
-
- m_pOther->startWithTarget(m_pTarget);
- }
-
- void CCActionEase::stop(void)
- {
-
- m_pOther->stop();
-
- CCActionInterval::stop();
- }
-
- void CCActionEase::update(float time)
- {
-
- m_pOther->update(time);
- }
-
- CCActionInterval* CCActionEase::reverse(void)
- {
-
- return CCActionEase::create(m_pOther->reverse());
- }
上面只是一个基类,它并未真正的提供速度的变化调节,下面还有一个基类,提供了一个速度调节系数值。
[cpp]
view plain copy
-
- class CC_DLL CCEaseRateAction : public CCActionEase
- {
- public:
-
- virtual ~CCEaseRateAction(void);
-
-
- inline void setRate(float rate) { m_fRate = rate; }
-
- inline float getRate(void) { return m_fRate; }
-
-
- bool initWithAction(CCActionInterval *pAction, float fRate);
-
- virtual CCObject* copyWithZone(CCZone* pZone);
-
- virtual CCActionInterval* reverse(void);
-
- public:
-
- CC_DEPRECATED_ATTRIBUTE static CCEaseRateAction* actionWithAction(CCActionInterval* pAction, float fRate);
-
-
- static CCEaseRateAction* create(CCActionInterval* pAction, float fRate);
-
- protected:
-
- float m_fRate;
- };
CPP实现:
[cpp]
view plain copy
-
- CCEaseRateAction* CCEaseRateAction::actionWithAction(CCActionInterval *pAction, float fRate)
- {
- return CCEaseRateAction::create(pAction, fRate);
- }
-
- CCEaseRateAction* CCEaseRateAction::create(CCActionInterval *pAction, float fRate)
- {
-
- CCEaseRateAction *pRet = new CCEaseRateAction();
- if (pRet)
- {
-
- if (pRet->initWithAction(pAction, fRate))
- {
- pRet->autorelease();
- }
- else
- {
-
- CC_SAFE_RELEASE_NULL(pRet);
- }
- }
-
- return pRet;
- }
-
-
- bool CCEaseRateAction::initWithAction(CCActionInterval *pAction, float fRate)
- {
-
- if (CCActionEase::initWithAction(pAction))
- {
-
- m_fRate = fRate;
- return true;
- }
-
- return false;
- }
-
-
- CCObject* CCEaseRateAction::copyWithZone(CCZone *pZone)
- {
- CCZone* pNewZone = NULL;
- CCEaseRateAction* pCopy = NULL;
- if(pZone && pZone->m_pCopyObject)
- {
-
- pCopy = (CCEaseRateAction*)(pZone->m_pCopyObject);
- }
- else
- {
- pCopy = new CCEaseRateAction();
- pNewZone = new CCZone(pCopy);
- }
-
- pCopy->initWithAction((CCActionInterval*)(m_pOther->copy()->autorelease()), m_fRate);
-
- CC_SAFE_DELETE(pNewZone);
- return pCopy;
- }
-
-
- CCEaseRateAction::~CCEaseRateAction(void)
- {
- }
-
- CCActionInterval* CCEaseRateAction::reverse(void)
- {
- return CCEaseRateAction::create(m_pOther->reverse(), 1 / m_fRate);
- }
第二个类有了速度属性,但这个速度属性并未对动画起任何作用。后面的类由这个带速度属性的动画基类派生,真正实现相应的变速效果。
[cpp]
view plain copy
-
- class CC_DLL CCEaseIn : public CCEaseRateAction
- {
- public:
-
- virtual void update(float time);
-
- virtual CCActionInterval* reverse(void);
-
- virtual CCObject* copyWithZone(CCZone* pZone);
- public:
-
- CC_DEPRECATED_ATTRIBUTE static CCEaseIn* actionWithAction(CCActionInterval* pAction, float fRate);
-
-
- static CCEaseIn* create(CCActionInterval* pAction, float fRate);
- };
CPP:
[cpp]
view plain copy
-
- CCEaseIn* CCEaseIn::actionWithAction(CCActionInterval *pAction, float fRate)
- {
- return CCEaseIn::create(pAction, fRate);
- }
-
- CCEaseIn* CCEaseIn::create(CCActionInterval *pAction, float fRate)
- {
- CCEaseIn *pRet = new CCEaseIn();
- if (pRet)
- {
- if (pRet->initWithAction(pAction, fRate))
- {
- pRet->autorelease();
- }
- else
- {
- CC_SAFE_RELEASE_NULL(pRet);
- }
- }
-
- return pRet;
- }
-
- CCObject* CCEaseIn::copyWithZone(CCZone *pZone)
- {
- CCZone* pNewZone = NULL;
- CCEaseIn* pCopy = NULL;
- if(pZone && pZone->m_pCopyObject)
- {
-
- pCopy = (CCEaseIn*)(pZone->m_pCopyObject);
- }
- else
- {
- pCopy = new CCEaseIn();
- pNewZone = new CCZone(pCopy);
- }
-
- pCopy->initWithAction((CCActionInterval*)(m_pOther->copy()->autorelease()), m_fRate);
-
- CC_SAFE_DELETE(pNewZone);
- return pCopy;
- }
-
- void CCEaseIn::update(float time)
- {
-
- m_pOther->update(powf(time, m_fRate));
-
- }
-
-
- CCActionInterval* CCEaseIn::reverse(void)
- {
- return CCEaseIn::create(m_pOther->reverse(),m_fRate);
- }
[cpp]
view plain copy
-
- class CC_DLL CCEaseOut : public CCEaseRateAction
- {
- public:
-
- virtual void update(float time);
-
- virtual CCActionInterval* reverse(void);
-
- virtual CCObject* copyWithZone(CCZone* pZone);
-
- public:
-
- CC_DEPRECATED_ATTRIBUTE static CCEaseOut* actionWithAction(CCActionInterval* pAction, float fRate);
-
-
- static CCEaseOut* create(CCActionInterval* pAction, float fRate);
- };
CPP:
[cpp]
view plain copy
-
- CCEaseOut* CCEaseOut::actionWithAction(CCActionInterval *pAction, float fRate)
- {
- return CCEaseOut::create(pAction, fRate);
- }
-
- CCEaseOut* CCEaseOut::create(CCActionInterval *pAction, float fRate)
- {
- CCEaseOut *pRet = new CCEaseOut();
- if (pRet)
- {
- if (pRet->initWithAction(pAction, fRate))
- {
- pRet->autorelease();
- }
- else
- {
- CC_SAFE_RELEASE_NULL(pRet);
- }
- }
-
- return pRet;
- }
-
- CCObject* CCEaseOut::copyWithZone(CCZone *pZone)
- {
- CCZone* pNewZone = NULL;
- CCEaseOut* pCopy = NULL;
- if(pZone && pZone->m_pCopyObject)
- {
-
- pCopy = (CCEaseOut*)(pZone->m_pCopyObject);
- }
- else
- {
- pCopy = new CCEaseOut();
- pNewZone = new CCZone(pCopy);
- }
-
- pCopy->initWithAction((CCActionInterval*)(m_pOther->copy()->autorelease()), m_fRate);
-
- CC_SAFE_DELETE(pNewZone);
- return pCopy;
- }
-
- void CCEaseOut::update(float time)
- {
-
- m_pOther->update(powf(time, 1 / m_fRate));
- }
-
- CCActionInterval* CCEaseOut::reverse()
- {
- return CCEaseOut::create(m_pOther->reverse(), 1 / m_fRate);
- }
[cpp]
view plain copy
- class CC_DLL CCEaseInOut : public CCEaseRateAction
- {
- public:
-
- virtual void update(float time);
-
- virtual CCActionInterval* reverse(void);
-
- virtual CCObject* copyWithZone(CCZone* pZone);
-
- public:
-
- CC_DEPRECATED_ATTRIBUTE static CCEaseInOut* actionWithAction(CCActionInterval* pAction, float fRate);
-
-
- static CCEaseInOut* create(CCActionInterval* pAction, float fRate);
- };
-
- CCEaseInOut* CCEaseInOut::actionWithAction(CCActionInterval *pAction, float fRate)
- {
- return CCEaseInOut::create(pAction, fRate);
- }
-
- CCEaseInOut* CCEaseInOut::create(CCActionInterval *pAction, float fRate)
- {
- CCEaseInOut *pRet = new CCEaseInOut();
- if (pRet)
- {
- if (pRet->initWithAction(pAction, fRate))
- {
- pRet->autorelease();
- }
- else
- {
- CC_SAFE_RELEASE_NULL(pRet);
- }
- }
-
- return pRet;
- }
-
- CCObject* CCEaseInOut::copyWithZone(CCZone *pZone)
- {
- CCZone* pNewZone = NULL;
- CCEaseInOut* pCopy = NULL;
- if(pZone && pZone->m_pCopyObject)
- {
-
- pCopy = (CCEaseInOut*)(pZone->m_pCopyObject);
- }
- else
- {
- pCopy = new CCEaseInOut();
- pNewZone = new CCZone(pCopy);
- }
-
- pCopy->initWithAction((CCActionInterval*)(m_pOther->copy()->autorelease()), m_fRate);
-
- CC_SAFE_DELETE(pNewZone);
- return pCopy;
- }
-
-
- void CCEaseInOut::update(float time)
- {
-
- time *= 2;
- if (time < 1)
- {
- m_pOther->update(0.5f * powf(time, m_fRate));
- }
- else
- {
- m_pOther->update(1.0f - 0.5f * powf(2-time, m_fRate));
- }
- }
-
- CCActionInterval* CCEaseInOut::reverse(void)
- {
- return CCEaseInOut::create(m_pOther->reverse(), m_fRate);
- }
[cpp]
view plain copy
- class CC_DLL CCEaseExponentialIn : public CCActionEase
- {
- public:
-
- virtual void update(float time);
-
- virtual CCActionInterval* reverse(void);
-
- virtual CCObject* copyWithZone(CCZone* pZone);
-
- public:
-
- CC_DEPRECATED_ATTRIBUTE static CCEaseExponentialIn* actionWithAction(CCActionInterval* pAction);
-
- static CCEaseExponentialIn* create(CCActionInterval* pAction);
- };
-
- CCEaseExponentialIn* CCEaseExponentialIn::actionWithAction(CCActionInterval* pAction)
- {
- return CCEaseExponentialIn::create(pAction);
- }
-
- CCEaseExponentialIn* CCEaseExponentialIn::create(CCActionInterval* pAction)
- {
- CCEaseExponentialIn *pRet = new CCEaseExponentialIn();
- if (pRet)
- {
- if (pRet->initWithAction(pAction))
- {
- pRet->autorelease();
- }
- else
- {
- CC_SAFE_RELEASE_NULL(pRet);
- }
- }
-
- return pRet;
- }
-
- CCObject* CCEaseExponentialIn::copyWithZone(CCZone *pZone)
- {
- CCZone* pNewZone = NULL;
- CCEaseExponentialIn* pCopy = NULL;
- if(pZone && pZone->m_pCopyObject)
- {
-
- pCopy = (CCEaseExponentialIn*)(pZone->m_pCopyObject);
- }
- else
- {
- pCopy = new CCEaseExponentialIn();
- pNewZone = new CCZone(pCopy);
- }
-
- pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()));
-
- CC_SAFE_DELETE(pNewZone);
- return pCopy;
- }
-
-
- void CCEaseExponentialIn::update(float time)
- {
-
- m_pOther->update(time == 0 ? 0 : powf(2, 10 * (time/1 - 1)) - 1 * 0.001f);
- }
-
-
- CCActionInterval* CCEaseExponentialIn::reverse(void)
- {
- return CCEaseExponentialOut::create(m_pOther->reverse());
- }
[cpp]
view plain copy
- class CC_DLL CCEaseExponentialOut : public CCActionEase
- {
- public:
-
- virtual void update(float time);
-
- virtual CCActionInterval* reverse(void);
-
- virtual CCObject* copyWithZone(CCZone* pZone);
-
- public:
-
- CC_DEPRECATED_ATTRIBUTE static CCEaseExponentialOut* actionWithAction(CCActionInterval* pAction);
-
- static CCEaseExponentialOut* create(CCActionInterval* pAction);
- };
-
- CCEaseExponentialOut* CCEaseExponentialOut::actionWithAction(CCActionInterval* pAction)
- {
- return CCEaseExponentialOut::create(pAction);
- }
-
- CCEaseExponentialOut* CCEaseExponentialOut::create(CCActionInterval* pAction)
- {
- CCEaseExponentialOut *pRet = new CCEaseExponentialOut();
- if (pRet)
- {
- if (pRet->initWithAction(pAction))
- {
- pRet->autorelease();
- }
- else
- {
- CC_SAFE_RELEASE_NULL(pRet);
- }
- }
-
- return pRet;
- }
-
- CCObject* CCEaseExponentialOut::copyWithZone(CCZone *pZone)
- {
- CCZone* pNewZone = NULL;
- CCEaseExponentialOut* pCopy = NULL;
- if(pZone && pZone->m_pCopyObject)
- {
-
- pCopy = (CCEaseExponentialOut*)(pZone->m_pCopyObject);
- }
- else
- {
- pCopy = new CCEaseExponentialOut();
- pNewZone = new CCZone(pCopy);
- }
-
- pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()));
-
- CC_SAFE_DELETE(pNewZone);
- return pCopy;
- }
-
- void CCEaseExponentialOut::update(float time)
- {
-
-
- m_pOther->update(time == 1 ? 1 : (-powf(2, -10 * time / 1) + 1));
- }
-
- CCActionInterval* CCEaseExponentialOut::reverse(void)
- {
- return CCEaseExponentialIn::create(m_pOther->reverse());
- }
[cpp]
view plain copy
- class CC_DLL CCEaseExponentialInOut : public CCActionEase
- {
- public:
-
- virtual void update(float time);
-
- virtual CCActionInterval* reverse(void);
-
- virtual CCObject* copyWithZone(CCZone* pZone);
- public:
-
- CC_DEPRECATED_ATTRIBUTE static CCEaseExponentialInOut* actionWithAction(CCActionInterval* pAction);
-
-
- static CCEaseExponentialInOut* create(CCActionInterval* pAction);
- };
-
- CCEaseExponentialInOut* CCEaseExponentialInOut::actionWithAction(CCActionInterval *pAction)
- {
- return CCEaseExponentialInOut::create(pAction);
- }
-
- CCEaseExponentialInOut* CCEaseExponentialInOut::create(CCActionInterval *pAction)
- {
- CCEaseExponentialInOut *pRet = new CCEaseExponentialInOut();
- if (pRet)
- {
- if (pRet->initWithAction(pAction))
- {
- pRet->autorelease();
- }
- else
- {
- CC_SAFE_RELEASE_NULL(pRet);
- }
- }
-
- return pRet;
- }
-
- CCObject* CCEaseExponentialInOut::copyWithZone(CCZone *pZone)
- {
- CCZone* pNewZone = NULL;
- CCEaseExponentialInOut* pCopy = NULL;
- if(pZone && pZone->m_pCopyObject)
- {
-
- pCopy = (CCEaseExponentialInOut*)(pZone->m_pCopyObject);
- }
- else
- {
- pCopy = new CCEaseExponentialInOut();
- pNewZone = new CCZone(pCopy);
- }
-
- pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()));
-
- CC_SAFE_DELETE(pNewZone);
- return pCopy;
- }
-
- void CCEaseExponentialInOut::update(float time)
- {
-
-
- time /= 0.5f;
- if (time < 1)
- {
- time = 0.5f * powf(2, 10 * (time - 1));
- }
- else
- {
- time = 0.5f * (-powf(2, -10 * (time - 1)) + 2);
- }
-
- m_pOther->update(time);
- }
-
- CCActionInterval* CCEaseExponentialInOut::reverse()
- {
- return CCEaseExponentialInOut::create(m_pOther->reverse());
- }
[cpp]
view plain copy
-
- class CC_DLL CCEaseSineIn : public CCActionEase
- {
- public:
-
- virtual void update(float time);
-
- virtual CCActionInterval* reverse(void);
-
- virtual CCObject* copyWithZone(CCZone* pZone);
-
- public:
-
- CC_DEPRECATED_ATTRIBUTE static CCEaseSineIn* actionWithAction(CCActionInterval* pAction);
-
- static CCEaseSineIn* create(CCActionInterval* pAction);
- };
-
- CCEaseSineIn* CCEaseSineIn::actionWithAction(CCActionInterval* pAction)
- {
- return CCEaseSineIn::create(pAction);
- }
-
- CCEaseSineIn* CCEaseSineIn::create(CCActionInterval* pAction)
- {
- CCEaseSineIn *pRet = new CCEaseSineIn();
- if (pRet)
- {
- if (pRet->initWithAction(pAction))
- {
- pRet->autorelease();
- }
- else
- {
- CC_SAFE_RELEASE_NULL(pRet);
- }
- }
-
- return pRet;
- }
-
- CCObject* CCEaseSineIn::copyWithZone(CCZone *pZone)
- {
- CCZone* pNewZone = NULL;
- CCEaseSineIn* pCopy = NULL;
- if(pZone && pZone->m_pCopyObject)
- {
-
- pCopy = (CCEaseSineIn*)(pZone->m_pCopyObject);
- }
- else
- {
- pCopy = new CCEaseSineIn();
- pNewZone = new CCZone(pCopy);
- }
-
- pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()));
-
- CC_SAFE_DELETE(pNewZone);
- return pCopy;
- }
-
- void CCEaseSineIn::update(float time)
- {
-
- m_pOther->update(-1 * cosf(time * (float)M_PI_2) + 1);
- }
-
- CCActionInterval* CCEaseSineIn::reverse(void)
- {
- return CCEaseSineOut::create(m_pOther->reverse());
- }
[cpp]
view plain copy
-
- class CC_DLL CCEaseSineOut : public CCActionEase
- {
- public:
-
- virtual void update(float time);
-
- virtual CCActionInterval* reverse(void);
-
- virtual CCObject* copyWithZone(CCZone* pZone);
-
- public:
-
- CC_DEPRECATED_ATTRIBUTE static CCEaseSineOut* actionWithAction(CCActionInterval* pAction);
-
- static CCEaseSineOut* create(CCActionInterval* pAction);
- };
-
- CCEaseSineOut* CCEaseSineOut::actionWithAction(CCActionInterval* pAction)
- {
- return CCEaseSineOut::create(pAction);
- }
-
- CCEaseSineOut* CCEaseSineOut::create(CCActionInterval* pAction)
- {
- CCEaseSineOut *pRet = new CCEaseSineOut();
- if (pRet)
- {
- if (pRet->initWithAction(pAction))
- {
- pRet->autorelease();
- }
- else
- {
- CC_SAFE_RELEASE_NULL(pRet);
- }
- }
-
- return pRet;
- }
-
- CCObject* CCEaseSineOut::copyWithZone(CCZone *pZone)
- {
- CCZone* pNewZone = NULL;
- CCEaseSineOut* pCopy = NULL;
- if(pZone && pZone->m_pCopyObject)
- {
-
- pCopy = (CCEaseSineOut*)(pZone->m_pCopyObject);
- }
- else
- {
- pCopy = new CCEaseSineOut();
- pNewZone = new CCZone(pCopy);
- }
-
- pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()));
-
- CC_SAFE_DELETE(pNewZone);
- return pCopy;
- }
-
- void CCEaseSineOut::update(float time)
- {
-
-
- m_pOther->update(sinf(time * (float)M_PI_2));
- }
-
- CCActionInterval* CCEaseSineOut::reverse(void)
- {
- return CCEaseSineIn::create(m_pOther->reverse());
- }
[cpp]
view plain copy
-
- class CC_DLL CCEaseSineInOut : public CCActionEase
- {
- public:
-
- virtual void update(float time);
-
- virtual CCActionInterval* reverse(void);
-
- virtual CCObject* copyWithZone(CCZone* pZone);
-
- public:
-
- CC_DEPRECATED_ATTRIBUTE static CCEaseSineInOut* actionWithAction(CCActionInterval* pAction);
-
- static CCEaseSineInOut* create(CCActionInterval* pAction);
- };
-
-
- CCEaseSineInOut* CCEaseSineInOut::actionWithAction(CCActionInterval* pAction)
- {
- return CCEaseSineInOut::create(pAction);
- }
-
- CCEaseSineInOut* CCEaseSineInOut::create(CCActionInterval* pAction)
- {
- CCEaseSineInOut *pRet = new CCEaseSineInOut();
- if (pRet)
- {
- if (pRet->initWithAction(pAction))
- {
- pRet->autorelease();
- }
- else
- {
- CC_SAFE_RELEASE_NULL(pRet);
- }
- }
-
- return pRet;
- }
-
- CCObject* CCEaseSineInOut::copyWithZone(CCZone *pZone)
- {
- CCZone* pNewZone = NULL;
- CCEaseSineInOut* pCopy = NULL;
- if(pZone && pZone->m_pCopyObject)
- {
-
- pCopy = (CCEaseSineInOut*)(pZone->m_pCopyObject);
- }
- else
- {
- pCopy = new CCEaseSineInOut();
- pNewZone = new CCZone(pCopy);
- }
-
- pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()));
-
- CC_SAFE_DELETE(pNewZone);
- return pCopy;
- }
-
- void CCEaseSineInOut::update(float time)
- {
-
- m_pOther->update(-0.5f * (cosf((float)M_PI * time) - 1));
- }
-
-
- CCActionInterval* CCEaseSineInOut::reverse()
- {
- return CCEaseSineInOut::create(m_pOther->reverse());
- }
[cpp]
view plain copy
-
- class CC_DLL CCEaseElastic : public CCActionEase
- {
- public:
-
- inline float getPeriod(void) { return m_fPeriod; }
-
- inline void setPeriod(float fPeriod) { m_fPeriod = fPeriod; }
-
-
- bool initWithAction(CCActionInterval *pAction, float fPeriod = 0.3f);
-
- virtual CCActionInterval* reverse(void);
-
-
- virtual CCObject* copyWithZone(CCZone* pZone);
-
- public:
-
- CC_DEPRECATED_ATTRIBUTE static CCEaseElastic* actionWithAction(CCActionInterval *pAction, float fPeriod = 0.3f);
-
- static CCEaseElastic* create(CCActionInterval *pAction, float fPeriod = 0.3f);
- protected:
-
- float m_fPeriod;
- };
-
-
- CCEaseElastic* CCEaseElastic::actionWithAction(CCActionInterval *pAction, float fPeriod)
- {
- return CCEaseElastic::create(pAction, fPeriod);
- }
-
- CCEaseElastic* CCEaseElastic::create(CCActionInterval *pAction, float fPeriod)
- {
- CCEaseElastic *pRet = new CCEaseElastic();
- if (pRet)
- {
- if (pRet->initWithAction(pAction, fPeriod))
- {
- pRet->autorelease();
- }
- else
- {
- CC_SAFE_RELEASE_NULL(pRet);
- }
- }
-
- return pRet;
- }
-
- bool CCEaseElastic::initWithAction(CCActionInterval *pAction, float fPeriod)
- {
- if (CCActionEase::initWithAction(pAction))
- {
-
- m_fPeriod = fPeriod;
- return true;
- }
-
- return false;
- }
-
-
- CCObject* CCEaseElastic::copyWithZone(CCZone *pZone)
- {
- CCZone* pNewZone = NULL;
- CCEaseElastic* pCopy = NULL;
- if(pZone && pZone->m_pCopyObject)
- {
-
- pCopy = (CCEaseElastic*)(pZone->m_pCopyObject);
- }
- else
- {
- pCopy = new CCEaseElastic();
- pNewZone = new CCZone(pCopy);
- }
-
- pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()), m_fPeriod);
-
- CC_SAFE_DELETE(pNewZone);
- return pCopy;
- }
-
- CCActionInterval* CCEaseElastic::reverse(void)
- {
- CCAssert(0, "Override me");
-
- return NULL;
- }
[cpp]
view plain copy
-
- class CC_DLL CCEaseElasticIn : public CCEaseElastic
- {
- public:
-
- virtual void update(float time);
-
- virtual CCActionInterval* reverse(void);
-
- virtual CCObject* copyWithZone(CCZone* pZone);
-
- public:
-
- CC_DEPRECATED_ATTRIBUTE static CCEaseElasticIn* actionWithAction(CCActionInterval *pAction, float fPeriod = 0.3f);
-
- static CCEaseElasticIn* create(CCActionInterval *pAction, float fPeriod = 0.3f);
- };
-
-
- CCEaseElasticIn* CCEaseElasticIn::actionWithAction(CCActionInterval *pAction, float fPeriod)
- {
- return CCEaseElasticIn::create(pAction, fPeriod);
- }
-
- CCEaseElasticIn* CCEaseElasticIn::create(CCActionInterval *pAction, float fPeriod)
- {
- CCEaseElasticIn *pRet = new CCEaseElasticIn();
- if (pRet)
- {
- if (pRet->initWithAction(pAction, fPeriod))
- {
- pRet->autorelease();
- }
- else
- {
- CC_SAFE_RELEASE_NULL(pRet);
- }
- }
-
- return pRet;
- }
-
- CCObject* CCEaseElasticIn::copyWithZone(CCZone *pZone)
- {
- CCZone* pNewZone = NULL;
- CCEaseElasticIn* pCopy = NULL;
- if(pZone && pZone->m_pCopyObject)
- {
-
- pCopy = (CCEaseElasticIn*)(pZone->m_pCopyObject);
- }
- else
- {
- pCopy = new CCEaseElasticIn();
- pNewZone = new CCZone(pCopy);
- }
-
- pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()), m_fPeriod);
-
- CC_SAFE_DELETE(pNewZone);
- return pCopy;
- }
-
- void CCEaseElasticIn::update(float time)
- {
-
-
- float newT = 0;
- if (time == 0 || time == 1)
- {
- newT = time;
- }
- else
- {
- float s = m_fPeriod / 4;
- time = time - 1;
- newT = -powf(2, 10 * time) * sinf((time - s) * M_PI_X_2 / m_fPeriod);
- }
-
- m_pOther->update(newT);
- }
-
- CCActionInterval* CCEaseElasticIn::reverse(void)
- {
- return CCEaseElasticOut::create(m_pOther->reverse(), m_fPeriod);
- }
[cpp]
view plain copy
- class CC_DLL CCEaseElasticOut : public CCEaseElastic
- {
- public:
-
- virtual void update(float time);
-
- virtual CCActionInterval* reverse(void);
-
- virtual CCObject* copyWithZone(CCZone* pZone);
-
- public:
-
- CC_DEPRECATED_ATTRIBUTE static CCEaseElasticOut* actionWithAction(CCActionInterval *pAction, float fPeriod = 0.3f);
-
-
- static CCEaseElasticOut* create(CCActionInterval *pAction, float fPeriod = 0.3f);
- };
-
-
- CCEaseElasticOut* CCEaseElasticOut::actionWithAction(CCActionInterval *pAction, float fPeriod)
- {
- return CCEaseElasticOut::create(pAction, fPeriod);
- }
-
- CCEaseElasticOut* CCEaseElasticOut::create(CCActionInterval *pAction, float fPeriod)
- {
- CCEaseElasticOut *pRet = new CCEaseElasticOut();
- if (pRet)
- {
- if (pRet->initWithAction(pAction, fPeriod))
- {
- pRet->autorelease();
- }
- else
- {
- CC_SAFE_RELEASE_NULL(pRet);
- }
- }
-
- return pRet;
- }
-
- CCObject *CCEaseElasticOut::copyWithZone(CCZone *pZone)
- {
- CCZone* pNewZone = NULL;
- CCEaseElasticOut* pCopy = NULL;
- if(pZone && pZone->m_pCopyObject)
- {
-
- pCopy = (CCEaseElasticOut*)(pZone->m_pCopyObject);
- }
- else
- {
- pCopy = new CCEaseElasticOut();
- pNewZone = new CCZone(pCopy);
- }
-
- pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()), m_fPeriod);
-
- CC_SAFE_DELETE(pNewZone);
- return pCopy;
- }
-
- void CCEaseElasticOut::update(float time)
- {
-
-
- float newT = 0;
- if (time == 0 || time == 1)
- {
- newT = time;
- }
- else
- {
- float s = m_fPeriod / 4;
- newT = powf(2, -10 * time) * sinf((time - s) * M_PI_X_2 / m_fPeriod) + 1;
- }
-
- m_pOther->update(newT);
- }
-
- CCActionInterval* CCEaseElasticOut::reverse(void)
- {
- return CCEaseElasticIn::create(m_pOther->reverse(), m_fPeriod);
- }
[cpp]
view plain copy
- class CC_DLL CCEaseElasticInOut : public CCEaseElastic
- {
- public:
-
- virtual void update(float time);
-
- virtual CCActionInterval* reverse(void);
-
- virtual CCObject* copyWithZone(CCZone* pZone);
-
- public:
-
- CC_DEPRECATED_ATTRIBUTE static CCEaseElasticInOut* actionWithAction(CCActionInterval *pAction, float fPeriod = 0.3f);
-
-
- static CCEaseElasticInOut* create(CCActionInterval *pAction, float fPeriod = 0.3f);
- };
-
- CCEaseElasticInOut* CCEaseElasticInOut::actionWithAction(CCActionInterval *pAction, float fPeriod)
- {
- return CCEaseElasticInOut::create(pAction, fPeriod);
- }
-
- CCEaseElasticInOut* CCEaseElasticInOut::create(CCActionInterval *pAction, float fPeriod)
- {
- CCEaseElasticInOut *pRet = new CCEaseElasticInOut();
- if (pRet)
- {
- if (pRet->initWithAction(pAction, fPeriod))
- {
- pRet->autorelease();
- }
- else
- {
- CC_SAFE_RELEASE_NULL(pRet);
- }
- }
-
- return pRet;
- }
-
- CCObject* CCEaseElasticInOut::copyWithZone(CCZone *pZone)
- {
- CCZone* pNewZone = NULL;
- CCEaseElasticInOut* pCopy = NULL;
- if(pZone && pZone->m_pCopyObject)
- {
-
- pCopy = (CCEaseElasticInOut*)(pZone->m_pCopyObject);
- }
- else
- {
- pCopy = new CCEaseElasticInOut();
- pNewZone = new CCZone(pCopy);
- }
-
- pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()), m_fPeriod);
-
- CC_SAFE_DELETE(pNewZone);
- return pCopy;
-
- }
-
- void CCEaseElasticInOut::update(float time)
- {
-
-
- float newT = 0;
- if (time == 0 || time == 1)
- {
- newT = time;
- }
- else
- {
- time = time * 2;
- if (! m_fPeriod)
- {
- m_fPeriod = 0.3f * 1.5f;
- }
-
- float s = m_fPeriod / 4;
-
- time = time - 1;
- if (time < 0)
- {
- newT = -0.5f * powf(2, 10 * time) * sinf((time -s) * M_PI_X_2 / m_fPeriod);
- }
- else
- {
- newT = powf(2, -10 * time) * sinf((time - s) * M_PI_X_2 / m_fPeriod) * 0.5f + 1;
- }
- }
-
- m_pOther->update(newT);
- }
-
- CCActionInterval* CCEaseElasticInOut::reverse(void)
- {
- return CCEaseElasticInOut::create(m_pOther->reverse(), m_fPeriod);
- }
[cpp]
view plain copy
-
- class CC_DLL CCEaseBounce : public CCActionEase
- {
- public:
-
- float bounceTime(float time);
-
- virtual CCObject* copyWithZone(CCZone* pZone);
-
- virtual CCActionInterval* reverse();
-
- public:
-
- CC_DEPRECATED_ATTRIBUTE static CCEaseBounce* actionWithAction(CCActionInterval* pAction);
-
- static CCEaseBounce* create(CCActionInterval* pAction);
- };
-
-
- CCEaseBounce* CCEaseBounce::actionWithAction(CCActionInterval* pAction)
- {
- return CCEaseBounce::create(pAction);
- }
-
- CCEaseBounce* CCEaseBounce::create(CCActionInterval* pAction)
- {
- CCEaseBounce *pRet = new CCEaseBounce();
- if (pRet)
- {
- if (pRet->initWithAction(pAction))
- {
- pRet->autorelease();
- }
- else
- {
- CC_SAFE_RELEASE_NULL(pRet);
- }
- }
-
- return pRet;
- }
-
- CCObject* CCEaseBounce::copyWithZone(CCZone *pZone)
- {
- CCZone* pNewZone = NULL;
- CCEaseBounce* pCopy = NULL;
- if(pZone && pZone->m_pCopyObject)
- {
-
- pCopy = (CCEaseBounce*)(pZone->m_pCopyObject);
- }
- else
- {
- pCopy = new CCEaseBounce();
- pNewZone = new CCZone(pCopy);
- }
-
- pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()));
-
- CC_SAFE_DELETE(pNewZone);
- return pCopy;
- }
-
- float CCEaseBounce::bounceTime(float time)
- {
-
-
- if (time < 1 / 2.75)
- {
- return 7.5625f * time * time;
- } else
- if (time < 2 / 2.75)
- {
- time -= 1.5f / 2.75f;
- return 7.5625f * time * time + 0.75f;
- } else
- if(time < 2.5 / 2.75)
- {
- time -= 2.25f / 2.75f;
- return 7.5625f * time * time + 0.9375f;
- }
-
- time -= 2.625f / 2.75f;
- return 7.5625f * time * time + 0.984375f;
- }
-
- CCActionInterval* CCEaseBounce::reverse()
- {
- return CCEaseBounce::create(m_pOther->reverse());
- }
[cpp]
view plain copy
-
- class CC_DLL CCEaseBounceIn : public CCEaseBounce
- {
- public:
-
- virtual void update(float time);
-
- virtual CCActionInterval* reverse(void);
-
- virtual CCObject* copyWithZone(CCZone* pZone);
-
- public:
-
- CC_DEPRECATED_ATTRIBUTE static CCEaseBounceIn* actionWithAction(CCActionInterval* pAction);
-
- static CCEaseBounceIn* create(CCActionInterval* pAction);
- };
-
- CCEaseBounceIn* CCEaseBounceIn::actionWithAction(CCActionInterval* pAction)
- {
- return CCEaseBounceIn::create(pAction);
- }
-
- CCEaseBounceIn* CCEaseBounceIn::create(CCActionInterval* pAction)
- {
- CCEaseBounceIn *pRet = new CCEaseBounceIn();
- if (pRet)
- {
- if (pRet->initWithAction(pAction))
- {
- pRet->autorelease();
- }
- else
- {
- CC_SAFE_RELEASE_NULL(pRet);
- }
- }
-
- return pRet;
- }
-
- CCObject* CCEaseBounceIn::copyWithZone(CCZone *pZone)
- {
- CCZone* pNewZone = NULL;
- CCEaseBounceIn* pCopy = NULL;
- if(pZone && pZone->m_pCopyObject)
- {
-
- pCopy = (CCEaseBounceIn*)(pZone->m_pCopyObject);
- }
- else
- {
- pCopy = new CCEaseBounceIn();
- pNewZone = new CCZone(pCopy);
- }
-
- pCopy->initWithAction((CCActionInterval *)(m_pOther->copy()->autorelease()));
-
- CC_SAFE_DELETE(pNewZone);
- return pCopy;
- }
-
- void CCEaseBounceIn::update(float time)
- {
-
-
-
- float newT = 1 - bounceTime(1 - time);
- m_pOther->update(newT);
- }
-
- CCActionInterval* CCEaseBounceIn::reverse(void)
- {
- return CCEaseBounceOut::create(m_pOther->reverse());
- }