axmol/cocos2dx/actions/CCActionEase.cpp

1354 lines
28 KiB
C++
Raw Normal View History

2011-03-19 10:34:26 +08:00
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
2011-03-19 10:34:26 +08:00
Copyright (c) 2008-2009 Jason Booth
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
2010-08-10 14:02:13 +08:00
/*
* Elastic, Back and Bounce actions based on code from:
* http://github.com/NikhilK/silverlightfx/
*
* by http://github.com/NikhilK
*/
2011-03-19 10:34:26 +08:00
#include "CCActionEase.h"
#include "cocoa/CCZone.h"
2011-03-19 10:34:26 +08:00
2012-04-18 18:43:45 +08:00
NS_CC_BEGIN
2010-08-10 14:02:13 +08:00
#ifndef M_PI_X_2
#define M_PI_X_2 (float)M_PI * 2.0f
#endif
//
// EaseAction
//
bool CCActionEase::initWithAction(CCActionInterval *pAction)
{
CCAssert(pAction != NULL, "");
if (CCActionInterval::initWithDuration(pAction->getDuration()))
{
_inner = pAction;
pAction->retain();
2010-08-10 14:02:13 +08:00
return true;
}
2010-08-10 14:02:13 +08:00
return false;
}
2010-08-10 14:02:13 +08:00
CCActionEase::~CCActionEase(void)
{
CC_SAFE_RELEASE(_inner);
}
void CCActionEase::startWithTarget(CCNode *pTarget)
{
CCActionInterval::startWithTarget(pTarget);
_inner->startWithTarget(_target);
}
void CCActionEase::stop(void)
{
_inner->stop();
CCActionInterval::stop();
}
2012-06-08 13:55:28 +08:00
void CCActionEase::update(float time)
{
_inner->update(time);
}
2010-08-10 14:02:13 +08:00
CCActionInterval* CCActionEase::getInnerAction()
{
return _inner;
}
//
// EaseRateAction
//
bool CCEaseRateAction::initWithAction(CCActionInterval *pAction, float fRate)
{
if (CCActionEase::initWithAction(pAction))
{
_rate = fRate;
return true;
}
2010-08-10 14:02:13 +08:00
return false;
}
2010-08-10 14:02:13 +08:00
CCEaseRateAction::~CCEaseRateAction(void)
{
}
2010-08-10 14:02:13 +08:00
//
// EeseIn
//
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);
}
}
2010-08-10 14:02:13 +08:00
return pRet;
}
CCEaseIn* CCEaseIn::clone() const
{
auto a = new CCEaseIn(*this);
a->initWithAction((CCActionInterval*)_inner->clone(), _rate);
a->autorelease();
return a;
}
CCObject* CCEaseIn::copyWithZone(CCZone *pZone)
{
CCZone* pNewZone = NULL;
CCEaseIn* pCopy = NULL;
if(pZone && pZone->_copyObject)
{
//in case of being called at sub class
pCopy = (CCEaseIn*)(pZone->_copyObject);
}
else
{
pCopy = new CCEaseIn();
pNewZone = new CCZone(pCopy);
}
2010-08-10 14:02:13 +08:00
pCopy->initWithAction((CCActionInterval*)(_inner->copy()->autorelease()), _rate);
2010-08-25 18:31:55 +08:00
CC_SAFE_DELETE(pNewZone);
return pCopy;
}
2012-06-08 13:55:28 +08:00
void CCEaseIn::update(float time)
{
_inner->update(powf(time, _rate));
}
2010-08-25 18:31:55 +08:00
CCEaseIn* CCEaseIn::reverse() const
{
return CCEaseIn::create(_inner->reverse(), 1 / _rate);
}
//
// EaseOut
//
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);
}
}
2010-08-10 14:02:13 +08:00
return pRet;
}
2010-08-10 14:02:13 +08:00
CCEaseOut* CCEaseOut::clone() const
{
auto a = new CCEaseOut(*this);
a->initWithAction((CCActionInterval*)_inner->clone(), _rate);
a->autorelease();
return a;
}
CCObject* CCEaseOut::copyWithZone(CCZone *pZone)
{
CCZone* pNewZone = NULL;
CCEaseOut* pCopy = NULL;
if(pZone && pZone->_copyObject)
{
//in case of being called at sub class
pCopy = (CCEaseOut*)(pZone->_copyObject);
}
else
{
pCopy = new CCEaseOut();
pNewZone = new CCZone(pCopy);
}
2010-08-10 14:02:13 +08:00
pCopy->initWithAction((CCActionInterval*)(_inner->copy()->autorelease()), _rate);
2010-08-25 18:31:55 +08:00
CC_SAFE_DELETE(pNewZone);
return pCopy;
}
2012-06-08 13:55:28 +08:00
void CCEaseOut::update(float time)
{
_inner->update(powf(time, 1 / _rate));
}
2010-08-25 18:31:55 +08:00
CCEaseOut* CCEaseOut::reverse() const
{
return CCEaseOut::create(_inner->reverse(), 1 / _rate);
}
//
// EaseInOut
//
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);
}
}
2010-08-10 14:02:13 +08:00
return pRet;
}
CCEaseInOut* CCEaseInOut::clone() const
{
auto a = new CCEaseInOut(*this);
a->initWithAction((CCActionInterval*)_inner->clone(), _rate);
a->autorelease();
return a;
}
CCObject* CCEaseInOut::copyWithZone(CCZone *pZone)
{
CCZone* pNewZone = NULL;
CCEaseInOut* pCopy = NULL;
if(pZone && pZone->_copyObject)
{
//in case of being called at sub class
pCopy = (CCEaseInOut*)(pZone->_copyObject);
}
else
{
pCopy = new CCEaseInOut();
pNewZone = new CCZone(pCopy);
}
2010-08-25 18:31:55 +08:00
pCopy->initWithAction((CCActionInterval*)(_inner->copy()->autorelease()), _rate);
CC_SAFE_DELETE(pNewZone);
return pCopy;
}
2010-08-10 14:02:13 +08:00
2012-06-08 13:55:28 +08:00
void CCEaseInOut::update(float time)
{
time *= 2;
if (time < 1)
{
_inner->update(0.5f * powf(time, _rate));
}
else
{
_inner->update(1.0f - 0.5f * powf(2-time, _rate));
}
}
2010-08-10 14:02:13 +08:00
// InOut and OutIn are symmetrical
CCEaseInOut* CCEaseInOut::reverse() const
{
return CCEaseInOut::create(_inner->reverse(), _rate);
}
2010-08-10 14:02:13 +08:00
//
// EaseExponentialIn
//
CCEaseExponentialIn* CCEaseExponentialIn::create(CCActionInterval* pAction)
{
CCEaseExponentialIn *pRet = new CCEaseExponentialIn();
if (pRet)
{
if (pRet->initWithAction(pAction))
{
pRet->autorelease();
}
else
{
CC_SAFE_RELEASE_NULL(pRet);
}
}
2010-08-10 14:02:13 +08:00
return pRet;
}
CCEaseExponentialIn* CCEaseExponentialIn::clone() const
{
auto a = new CCEaseExponentialIn(*this);
a->initWithAction((CCActionInterval *)_inner->clone());
a->autorelease();
return a;
}
CCObject* CCEaseExponentialIn::copyWithZone(CCZone *pZone)
{
CCZone* pNewZone = NULL;
CCEaseExponentialIn* pCopy = NULL;
if(pZone && pZone->_copyObject)
{
//in case of being called at sub class
pCopy = (CCEaseExponentialIn*)(pZone->_copyObject);
}
else
{
pCopy = new CCEaseExponentialIn();
pNewZone = new CCZone(pCopy);
}
pCopy->initWithAction((CCActionInterval *)(_inner->copy()->autorelease()));
CC_SAFE_DELETE(pNewZone);
return pCopy;
}
2012-06-08 13:55:28 +08:00
void CCEaseExponentialIn::update(float time)
{
_inner->update(time == 0 ? 0 : powf(2, 10 * (time/1 - 1)) - 1 * 0.001f);
}
CCActionEase * CCEaseExponentialIn::reverse() const
{
return CCEaseExponentialOut::create(_inner->reverse());
}
//
// EaseExponentialOut
//
CCEaseExponentialOut* CCEaseExponentialOut::create(CCActionInterval* pAction)
{
CCEaseExponentialOut *pRet = new CCEaseExponentialOut();
if (pRet)
{
if (pRet->initWithAction(pAction))
{
pRet->autorelease();
}
else
{
CC_SAFE_RELEASE_NULL(pRet);
}
}
2010-08-10 14:02:13 +08:00
return pRet;
}
CCEaseExponentialOut* CCEaseExponentialOut::clone() const
{
auto a = new CCEaseExponentialOut(*this);
a->initWithAction((CCActionInterval *)_inner->clone());
a->autorelease();
return a;
}
CCObject* CCEaseExponentialOut::copyWithZone(CCZone *pZone)
{
CCZone* pNewZone = NULL;
CCEaseExponentialOut* pCopy = NULL;
if(pZone && pZone->_copyObject)
{
//in case of being called at sub class
pCopy = (CCEaseExponentialOut*)(pZone->_copyObject);
}
else
{
pCopy = new CCEaseExponentialOut();
pNewZone = new CCZone(pCopy);
}
pCopy->initWithAction((CCActionInterval *)(_inner->copy()->autorelease()));
CC_SAFE_DELETE(pNewZone);
return pCopy;
}
2010-08-25 18:31:55 +08:00
2012-06-08 13:55:28 +08:00
void CCEaseExponentialOut::update(float time)
{
_inner->update(time == 1 ? 1 : (-powf(2, -10 * time / 1) + 1));
}
CCActionEase* CCEaseExponentialOut::reverse() const
{
return CCEaseExponentialIn::create(_inner->reverse());
}
2010-08-25 18:31:55 +08:00
//
// EaseExponentialInOut
//
CCEaseExponentialInOut* CCEaseExponentialInOut::create(CCActionInterval *pAction)
{
CCEaseExponentialInOut *pRet = new CCEaseExponentialInOut();
if (pRet)
{
if (pRet->initWithAction(pAction))
{
pRet->autorelease();
}
else
{
CC_SAFE_RELEASE_NULL(pRet);
}
}
2010-08-10 14:02:13 +08:00
return pRet;
}
CCEaseExponentialInOut* CCEaseExponentialInOut::clone() const
{
auto a = new CCEaseExponentialInOut(*this);
a->initWithAction((CCActionInterval *)_inner->clone());
a->autorelease();
return a;
}
CCObject* CCEaseExponentialInOut::copyWithZone(CCZone *pZone)
{
CCZone* pNewZone = NULL;
CCEaseExponentialInOut* pCopy = NULL;
if(pZone && pZone->_copyObject)
{
//in case of being called at sub class
pCopy = (CCEaseExponentialInOut*)(pZone->_copyObject);
}
else
{
pCopy = new CCEaseExponentialInOut();
pNewZone = new CCZone(pCopy);
}
pCopy->initWithAction((CCActionInterval *)(_inner->copy()->autorelease()));
CC_SAFE_DELETE(pNewZone);
return pCopy;
}
2010-08-25 18:31:55 +08:00
2012-06-08 13:55:28 +08:00
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);
}
2010-08-10 14:02:13 +08:00
_inner->update(time);
}
CCEaseExponentialInOut* CCEaseExponentialInOut::reverse() const
{
return CCEaseExponentialInOut::create(_inner->reverse());
}
//
// EaseSineIn
//
CCEaseSineIn* CCEaseSineIn::create(CCActionInterval* pAction)
{
CCEaseSineIn *pRet = new CCEaseSineIn();
if (pRet)
{
if (pRet->initWithAction(pAction))
{
pRet->autorelease();
}
else
{
CC_SAFE_RELEASE_NULL(pRet);
}
}
2010-08-10 14:02:13 +08:00
return pRet;
}
2010-08-25 18:31:55 +08:00
CCEaseSineIn* CCEaseSineIn::clone() const
{
auto a = new CCEaseSineIn(*this);
a->initWithAction((CCActionInterval *)_inner->clone());
a->autorelease();
return a;
}
CCObject* CCEaseSineIn::copyWithZone(CCZone *pZone)
{
CCZone* pNewZone = NULL;
CCEaseSineIn* pCopy = NULL;
if(pZone && pZone->_copyObject)
{
//in case of being called at sub class
pCopy = (CCEaseSineIn*)(pZone->_copyObject);
}
else
{
pCopy = new CCEaseSineIn();
pNewZone = new CCZone(pCopy);
}
pCopy->initWithAction((CCActionInterval *)(_inner->copy()->autorelease()));
CC_SAFE_DELETE(pNewZone);
return pCopy;
}
2012-06-08 13:55:28 +08:00
void CCEaseSineIn::update(float time)
{
_inner->update(-1 * cosf(time * (float)M_PI_2) + 1);
}
CCActionEase* CCEaseSineIn::reverse() const
{
return CCEaseSineOut::create(_inner->reverse());
}
//
// EaseSineOut
//
CCEaseSineOut* CCEaseSineOut::create(CCActionInterval* pAction)
{
CCEaseSineOut *pRet = new CCEaseSineOut();
if (pRet)
{
if (pRet->initWithAction(pAction))
{
pRet->autorelease();
}
else
{
CC_SAFE_RELEASE_NULL(pRet);
}
}
2010-08-10 14:02:13 +08:00
return pRet;
}
CCEaseSineOut* CCEaseSineOut::clone() const
{
auto a = new CCEaseSineOut(*this);
a->initWithAction((CCActionInterval *)_inner->clone());
a->autorelease();
return a;
}
CCObject* CCEaseSineOut::copyWithZone(CCZone *pZone)
{
CCZone* pNewZone = NULL;
CCEaseSineOut* pCopy = NULL;
if(pZone && pZone->_copyObject)
{
//in case of being called at sub class
pCopy = (CCEaseSineOut*)(pZone->_copyObject);
}
else
{
pCopy = new CCEaseSineOut();
pNewZone = new CCZone(pCopy);
}
pCopy->initWithAction((CCActionInterval *)(_inner->copy()->autorelease()));
CC_SAFE_DELETE(pNewZone);
return pCopy;
}
2010-08-25 18:31:55 +08:00
2012-06-08 13:55:28 +08:00
void CCEaseSineOut::update(float time)
{
_inner->update(sinf(time * (float)M_PI_2));
}
2010-08-25 18:31:55 +08:00
CCActionEase* CCEaseSineOut::reverse(void) const
{
return CCEaseSineIn::create(_inner->reverse());
}
//
// EaseSineInOut
//
CCEaseSineInOut* CCEaseSineInOut::create(CCActionInterval* pAction)
{
CCEaseSineInOut *pRet = new CCEaseSineInOut();
if (pRet)
{
if (pRet->initWithAction(pAction))
{
pRet->autorelease();
}
else
{
CC_SAFE_RELEASE_NULL(pRet);
}
}
2010-08-10 14:02:13 +08:00
return pRet;
}
CCEaseSineInOut* CCEaseSineInOut::clone() const
{
auto a = new CCEaseSineInOut(*this);
a->initWithAction((CCActionInterval *)_inner->clone());
a->autorelease();
return a;
}
CCObject* CCEaseSineInOut::copyWithZone(CCZone *pZone)
{
CCZone* pNewZone = NULL;
CCEaseSineInOut* pCopy = NULL;
if(pZone && pZone->_copyObject)
{
//in case of being called at sub class
pCopy = (CCEaseSineInOut*)(pZone->_copyObject);
}
else
{
pCopy = new CCEaseSineInOut();
pNewZone = new CCZone(pCopy);
}
pCopy->initWithAction((CCActionInterval *)(_inner->copy()->autorelease()));
CC_SAFE_DELETE(pNewZone);
return pCopy;
}
2010-08-25 18:31:55 +08:00
2012-06-08 13:55:28 +08:00
void CCEaseSineInOut::update(float time)
{
_inner->update(-0.5f * (cosf((float)M_PI * time) - 1));
}
2010-08-25 18:31:55 +08:00
CCEaseSineInOut* CCEaseSineInOut::reverse() const
{
return CCEaseSineInOut::create(_inner->reverse());
}
//
// EaseElastic
//
2010-08-10 14:02:13 +08:00
bool CCEaseElastic::initWithAction(CCActionInterval *pAction, float fPeriod/* = 0.3f*/)
{
if (CCActionEase::initWithAction(pAction))
{
_period = fPeriod;
return true;
}
2010-08-10 14:02:13 +08:00
return false;
}
//
// EaseElasticIn
//
CCEaseElasticIn* CCEaseElasticIn::create(CCActionInterval *pAction)
{
return CCEaseElasticIn::create(pAction, 0.3f);
}
CCEaseElasticIn* CCEaseElasticIn::create(CCActionInterval *pAction, float fPeriod/* = 0.3f*/)
{
CCEaseElasticIn *pRet = new CCEaseElasticIn();
if (pRet)
{
if (pRet->initWithAction(pAction, fPeriod))
{
pRet->autorelease();
}
else
{
CC_SAFE_RELEASE_NULL(pRet);
}
}
2010-08-10 14:02:13 +08:00
return pRet;
}
CCEaseElasticIn* CCEaseElasticIn::clone() const
{
auto a = new CCEaseElasticIn(*this);
a->initWithAction((CCActionInterval *)_inner->clone(), _period);
a->autorelease();
return a;
}
CCObject* CCEaseElasticIn::copyWithZone(CCZone *pZone)
{
CCZone* pNewZone = NULL;
CCEaseElasticIn* pCopy = NULL;
if(pZone && pZone->_copyObject)
{
//in case of being called at sub class
pCopy = (CCEaseElasticIn*)(pZone->_copyObject);
}
else
{
pCopy = new CCEaseElasticIn();
pNewZone = new CCZone(pCopy);
}
2010-08-10 14:02:13 +08:00
pCopy->initWithAction((CCActionInterval *)(_inner->copy()->autorelease()), _period);
2010-08-25 18:31:55 +08:00
CC_SAFE_DELETE(pNewZone);
return pCopy;
}
2010-08-25 18:31:55 +08:00
2012-06-08 13:55:28 +08:00
void CCEaseElasticIn::update(float time)
{
2012-06-08 13:55:28 +08:00
float newT = 0;
if (time == 0 || time == 1)
{
newT = time;
}
else
{
float s = _period / 4;
time = time - 1;
newT = -powf(2, 10 * time) * sinf((time - s) * M_PI_X_2 / _period);
}
_inner->update(newT);
}
2010-08-25 18:31:55 +08:00
CCEaseElastic* CCEaseElasticIn::reverse() const
{
return CCEaseElasticOut::create(_inner->reverse(), _period);
}
//
// EaseElasticOut
//
CCEaseElasticOut* CCEaseElasticOut::create(CCActionInterval *pAction)
{
return CCEaseElasticOut::create(pAction, 0.3f);
}
CCEaseElasticOut* CCEaseElasticOut::create(CCActionInterval *pAction, float fPeriod/* = 0.3f*/)
{
CCEaseElasticOut *pRet = new CCEaseElasticOut();
if (pRet)
{
if (pRet->initWithAction(pAction, fPeriod))
{
pRet->autorelease();
}
else
{
CC_SAFE_RELEASE_NULL(pRet);
}
}
2010-08-10 14:02:13 +08:00
return pRet;
}
CCEaseElasticOut* CCEaseElasticOut::clone() const
{
auto a = new CCEaseElasticOut(*this);
a->initWithAction((CCActionInterval *)_inner->clone(), _period);
a->autorelease();
return a;
}
CCObject *CCEaseElasticOut::copyWithZone(CCZone *pZone)
{
CCZone* pNewZone = NULL;
CCEaseElasticOut* pCopy = NULL;
if(pZone && pZone->_copyObject)
{
//in case of being called at sub class
pCopy = (CCEaseElasticOut*)(pZone->_copyObject);
}
else
{
pCopy = new CCEaseElasticOut();
pNewZone = new CCZone(pCopy);
}
2010-08-25 18:31:55 +08:00
pCopy->initWithAction((CCActionInterval *)(_inner->copy()->autorelease()), _period);
CC_SAFE_DELETE(pNewZone);
return pCopy;
}
2010-08-25 18:31:55 +08:00
2012-06-08 13:55:28 +08:00
void CCEaseElasticOut::update(float time)
{
2012-06-08 13:55:28 +08:00
float newT = 0;
if (time == 0 || time == 1)
{
newT = time;
}
else
{
float s = _period / 4;
newT = powf(2, -10 * time) * sinf((time - s) * M_PI_X_2 / _period) + 1;
}
2010-08-25 18:31:55 +08:00
_inner->update(newT);
}
CCEaseElastic* CCEaseElasticOut::reverse() const
{
return CCEaseElasticIn::create(_inner->reverse(), _period);
}
//
// EaseElasticInOut
//
CCEaseElasticInOut* CCEaseElasticInOut::create(CCActionInterval *pAction)
{
return CCEaseElasticInOut::create(pAction, 0.3f);
}
CCEaseElasticInOut* CCEaseElasticInOut::create(CCActionInterval *pAction, float fPeriod/* = 0.3f*/)
{
CCEaseElasticInOut *pRet = new CCEaseElasticInOut();
if (pRet)
{
if (pRet->initWithAction(pAction, fPeriod))
{
pRet->autorelease();
}
else
{
CC_SAFE_RELEASE_NULL(pRet);
}
}
2010-08-10 14:02:13 +08:00
return pRet;
}
CCEaseElasticInOut* CCEaseElasticInOut::clone() const
{
auto a = new CCEaseElasticInOut(*this);
a->initWithAction((CCActionInterval *)_inner->clone(), _period);
a->autorelease();
return a;
}
CCObject* CCEaseElasticInOut::copyWithZone(CCZone *pZone)
{
CCZone* pNewZone = NULL;
CCEaseElasticInOut* pCopy = NULL;
if(pZone && pZone->_copyObject)
{
//in case of being called at sub class
pCopy = (CCEaseElasticInOut*)(pZone->_copyObject);
}
else
{
pCopy = new CCEaseElasticInOut();
pNewZone = new CCZone(pCopy);
}
2010-08-25 18:31:55 +08:00
pCopy->initWithAction((CCActionInterval *)(_inner->copy()->autorelease()), _period);
CC_SAFE_DELETE(pNewZone);
return pCopy;
}
2012-06-08 13:55:28 +08:00
void CCEaseElasticInOut::update(float time)
{
2012-06-08 13:55:28 +08:00
float newT = 0;
if (time == 0 || time == 1)
{
newT = time;
}
else
{
time = time * 2;
if (! _period)
{
_period = 0.3f * 1.5f;
}
float s = _period / 4;
time = time - 1;
if (time < 0)
{
newT = -0.5f * powf(2, 10 * time) * sinf((time -s) * M_PI_X_2 / _period);
}
else
{
newT = powf(2, -10 * time) * sinf((time - s) * M_PI_X_2 / _period) * 0.5f + 1;
}
}
_inner->update(newT);
}
2010-08-10 14:02:13 +08:00
CCEaseElasticInOut* CCEaseElasticInOut::reverse() const
{
return CCEaseElasticInOut::create(_inner->reverse(), _period);
}
2010-08-10 14:02:13 +08:00
//
// EaseBounce
//
2012-06-08 13:55:28 +08:00
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;
}
//
// EaseBounceIn
//
CCEaseBounceIn* CCEaseBounceIn::create(CCActionInterval* pAction)
{
CCEaseBounceIn *pRet = new CCEaseBounceIn();
if (pRet)
{
if (pRet->initWithAction(pAction))
{
pRet->autorelease();
}
else
{
CC_SAFE_RELEASE_NULL(pRet);
}
}
2010-08-10 14:02:13 +08:00
return pRet;
}
2010-08-10 14:02:13 +08:00
CCEaseBounceIn* CCEaseBounceIn::clone() const
{
auto a = new CCEaseBounceIn(*this);
a->initWithAction((CCActionInterval *)_inner->clone());
a->autorelease();
return a;
}
CCObject* CCEaseBounceIn::copyWithZone(CCZone *pZone)
{
CCZone* pNewZone = NULL;
CCEaseBounceIn* pCopy = NULL;
if(pZone && pZone->_copyObject)
{
//in case of being called at sub class
pCopy = (CCEaseBounceIn*)(pZone->_copyObject);
}
else
{
pCopy = new CCEaseBounceIn();
pNewZone = new CCZone(pCopy);
}
pCopy->initWithAction((CCActionInterval *)(_inner->copy()->autorelease()));
CC_SAFE_DELETE(pNewZone);
return pCopy;
}
2012-06-08 13:55:28 +08:00
void CCEaseBounceIn::update(float time)
{
2012-06-08 13:55:28 +08:00
float newT = 1 - bounceTime(1 - time);
_inner->update(newT);
}
CCEaseBounce* CCEaseBounceIn::reverse() const
{
return CCEaseBounceOut::create(_inner->reverse());
}
//
// EaseBounceOut
//
CCEaseBounceOut* CCEaseBounceOut::create(CCActionInterval* pAction)
{
CCEaseBounceOut *pRet = new CCEaseBounceOut();
if (pRet)
{
if (pRet->initWithAction(pAction))
{
pRet->autorelease();
}
else
{
CC_SAFE_RELEASE_NULL(pRet);
}
}
2010-08-10 14:02:13 +08:00
return pRet;
}
CCEaseBounceOut* CCEaseBounceOut::clone() const
{
auto a = new CCEaseBounceOut(*this);
a->initWithAction((CCActionInterval *)_inner->clone());
a->autorelease();
return a;
}
CCObject* CCEaseBounceOut::copyWithZone(CCZone *pZone)
{
CCZone* pNewZone = NULL;
CCEaseBounceOut* pCopy = NULL;
if(pZone && pZone->_copyObject)
{
//in case of being called at sub class
pCopy = (CCEaseBounceOut*)(pZone->_copyObject);
}
else
{
pCopy = new CCEaseBounceOut();
pNewZone = new CCZone(pCopy);
}
pCopy->initWithAction((CCActionInterval *)(_inner->copy()->autorelease()));
CC_SAFE_DELETE(pNewZone);
return pCopy;
}
2010-08-25 18:31:55 +08:00
2012-06-08 13:55:28 +08:00
void CCEaseBounceOut::update(float time)
{
2012-06-08 13:55:28 +08:00
float newT = bounceTime(time);
_inner->update(newT);
}
2010-08-25 18:31:55 +08:00
CCEaseBounce* CCEaseBounceOut::reverse() const
{
return CCEaseBounceIn::create(_inner->reverse());
}
//
// EaseBounceInOut
//
CCEaseBounceInOut* CCEaseBounceInOut::create(CCActionInterval* pAction)
{
CCEaseBounceInOut *pRet = new CCEaseBounceInOut();
if (pRet)
{
if (pRet->initWithAction(pAction))
{
pRet->autorelease();
}
else
{
CC_SAFE_RELEASE_NULL(pRet);
}
}
2010-08-10 14:02:13 +08:00
return pRet;
}
CCEaseBounceInOut* CCEaseBounceInOut::clone() const
{
auto a = new CCEaseBounceInOut(*this);
a->initWithAction((CCActionInterval *)_inner->clone());
a->autorelease();
return a;
}
CCObject* CCEaseBounceInOut::copyWithZone(CCZone *pZone)
{
CCZone* pNewZone = NULL;
CCEaseBounceInOut* pCopy = NULL;
if(pZone && pZone->_copyObject)
{
//in case of being called at sub class
pCopy = (CCEaseBounceInOut*)(pZone->_copyObject);
}
else
{
pCopy = new CCEaseBounceInOut();
pNewZone = new CCZone(pCopy);
}
pCopy->initWithAction((CCActionInterval *)(_inner->copy()->autorelease()));
CC_SAFE_DELETE(pNewZone);
return pCopy;
}
2010-08-25 18:31:55 +08:00
2012-06-08 13:55:28 +08:00
void CCEaseBounceInOut::update(float time)
{
2012-06-08 13:55:28 +08:00
float newT = 0;
if (time < 0.5f)
{
time = time * 2;
newT = (1 - bounceTime(1 - time)) * 0.5f;
}
else
{
newT = bounceTime(time * 2 - 1) * 0.5f + 0.5f;
}
2010-08-10 14:02:13 +08:00
_inner->update(newT);
}
CCEaseBounceInOut* CCEaseBounceInOut::reverse() const
{
return CCEaseBounceInOut::create(_inner->reverse());
}
//
// EaseBackIn
//
CCEaseBackIn* CCEaseBackIn::create(CCActionInterval *pAction)
{
CCEaseBackIn *pRet = new CCEaseBackIn();
if (pRet)
{
if (pRet->initWithAction(pAction))
{
pRet->autorelease();
}
else
{
CC_SAFE_RELEASE_NULL(pRet);
}
}
2010-08-10 14:02:13 +08:00
return pRet;
}
2010-08-25 18:31:55 +08:00
CCEaseBackIn* CCEaseBackIn::clone() const
{
auto a = new CCEaseBackIn(*this);
a->initWithAction((CCActionInterval *)_inner->clone());
a->autorelease();
return a;
}
CCObject* CCEaseBackIn::copyWithZone(CCZone *pZone)
{
CCZone* pNewZone = NULL;
CCEaseBackIn* pCopy = NULL;
if(pZone && pZone->_copyObject)
{
//in case of being called at sub class
pCopy = (CCEaseBackIn*)(pZone->_copyObject);
}
else
{
pCopy = new CCEaseBackIn();
pNewZone = new CCZone(pCopy);
}
pCopy->initWithAction((CCActionInterval *)(_inner->copy()->autorelease()));
CC_SAFE_DELETE(pNewZone);
return pCopy;
}
2012-06-08 13:55:28 +08:00
void CCEaseBackIn::update(float time)
{
2012-06-08 13:55:28 +08:00
float overshoot = 1.70158f;
_inner->update(time * time * ((overshoot + 1) * time - overshoot));
}
CCActionEase* CCEaseBackIn::reverse() const
{
return CCEaseBackOut::create(_inner->reverse());
}
//
// EaseBackOut
//
CCEaseBackOut* CCEaseBackOut::create(CCActionInterval* pAction)
{
CCEaseBackOut *pRet = new CCEaseBackOut();
if (pRet)
{
if (pRet->initWithAction(pAction))
{
pRet->autorelease();
}
else
{
CC_SAFE_RELEASE_NULL(pRet);
}
}
2010-08-10 14:02:13 +08:00
return pRet;
}
CCEaseBackOut* CCEaseBackOut::clone() const
{
auto a = new CCEaseBackOut(*this);
a->initWithAction((CCActionInterval *)_inner->clone());
a->autorelease();
return a;
}
CCObject* CCEaseBackOut::copyWithZone(CCZone *pZone)
{
CCZone* pNewZone = NULL;
CCEaseBackOut* pCopy = NULL;
if(pZone && pZone->_copyObject)
{
//in case of being called at sub class
pCopy = (CCEaseBackOut*)(pZone->_copyObject);
}
else
{
pCopy = new CCEaseBackOut();
pNewZone = new CCZone(pCopy);
}
pCopy->initWithAction((CCActionInterval *)(_inner->copy()->autorelease()));
CC_SAFE_DELETE(pNewZone);
return pCopy;
}
2010-08-25 18:31:55 +08:00
2012-06-08 13:55:28 +08:00
void CCEaseBackOut::update(float time)
{
2012-06-08 13:55:28 +08:00
float overshoot = 1.70158f;
time = time - 1;
_inner->update(time * time * ((overshoot + 1) * time + overshoot) + 1);
}
2010-08-25 18:31:55 +08:00
CCActionEase* CCEaseBackOut::reverse() const
{
return CCEaseBackIn::create(_inner->reverse());
}
//
// EaseBackInOut
//
CCEaseBackInOut* CCEaseBackInOut::create(CCActionInterval* pAction)
{
CCEaseBackInOut *pRet = new CCEaseBackInOut();
if (pRet)
{
if (pRet->initWithAction(pAction))
{
pRet->autorelease();
}
else
{
CC_SAFE_RELEASE_NULL(pRet);
}
}
2010-08-10 14:02:13 +08:00
return pRet;
}
2010-08-10 14:02:13 +08:00
CCEaseBackInOut* CCEaseBackInOut::clone() const
{
auto a = new CCEaseBackInOut(*this);
a->initWithAction((CCActionInterval *)_inner->clone());
a->autorelease();
return a;
}
CCObject* CCEaseBackInOut::copyWithZone(CCZone *pZone)
{
CCZone* pNewZone = NULL;
CCEaseBackInOut* pCopy = NULL;
if(pZone && pZone->_copyObject)
{
//in case of being called at sub class
pCopy = (CCEaseBackInOut*)(pZone->_copyObject);
}
else
{
pCopy = new CCEaseBackInOut();
pNewZone = new CCZone(pCopy);
}
pCopy->initWithAction((CCActionInterval *)(_inner->copy()->autorelease()));
CC_SAFE_DELETE(pNewZone);
return pCopy;
}
2010-08-25 18:31:55 +08:00
2012-06-08 13:55:28 +08:00
void CCEaseBackInOut::update(float time)
{
2012-06-08 13:55:28 +08:00
float overshoot = 1.70158f * 1.525f;
time = time * 2;
if (time < 1)
{
_inner->update((time * time * ((overshoot + 1) * time - overshoot)) / 2);
}
else
{
time = time - 2;
_inner->update((time * time * ((overshoot + 1) * time + overshoot)) / 2 + 1);
}
2010-08-10 14:02:13 +08:00
}
2012-04-18 18:43:45 +08:00
CCEaseBackInOut* CCEaseBackInOut::reverse() const
{
return CCEaseBackInOut::create(_inner->reverse());
}
2012-04-18 18:43:45 +08:00
NS_CC_END