mirror of https://github.com/axmolengine/axmol.git
refactor EaseIn with CCTweenFunction
This commit is contained in:
parent
ab11147eeb
commit
838c71b135
|
@ -32,6 +32,7 @@ THE SOFTWARE.
|
|||
*/
|
||||
|
||||
#include "CCActionEase.h"
|
||||
#include "CCTweenFunction.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -137,7 +138,9 @@ EaseIn* EaseIn::clone() const
|
|||
|
||||
void EaseIn::update(float time)
|
||||
{
|
||||
_inner->update(powf(time, _rate));
|
||||
TweenFunction funObj(_rate);
|
||||
_tweenFunction = &TweenFunction::easeIn;
|
||||
_inner->update(_tweenFunction(funObj,time));
|
||||
}
|
||||
|
||||
EaseIn* EaseIn::reverse() const
|
||||
|
|
|
@ -32,6 +32,7 @@ THE SOFTWARE.
|
|||
NS_CC_BEGIN
|
||||
|
||||
class Object;
|
||||
class TweenFunction;
|
||||
|
||||
/**
|
||||
* @addtogroup actions
|
||||
|
@ -65,7 +66,7 @@ protected:
|
|||
|
||||
/** The inner action */
|
||||
ActionInterval *_inner;
|
||||
std::function<float(float)> tweenFunction;
|
||||
std::function<float(const TweenFunction&, float)> _tweenFunction;
|
||||
|
||||
private:
|
||||
CC_DISALLOW_COPY_AND_ASSIGN(ActionEase);
|
||||
|
|
|
@ -30,6 +30,18 @@ NS_CC_BEGIN
|
|||
#define M_PI_X_2 (float)M_PI * 2.0f
|
||||
#endif
|
||||
|
||||
TweenFunction::TweenFunction()
|
||||
:_rate(0.0f)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TweenFunction::TweenFunction(float rate)
|
||||
:_rate(rate)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
float TweenFunction::tweenTo(float time, TweenType type, float *easingParam)
|
||||
{
|
||||
|
@ -475,6 +487,10 @@ float TweenFunction::customEase(float time, float *easingParam)
|
|||
return time;
|
||||
}
|
||||
|
||||
float TweenFunction::easeIn(float time) const
|
||||
{
|
||||
return powf(time, _rate);
|
||||
}
|
||||
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -26,6 +26,7 @@ THE SOFTWARE.
|
|||
#define __CCTWEENFUNCTION_H__
|
||||
|
||||
#include "CCPlatformMacros.h"
|
||||
#include "ccMacros.h"
|
||||
#include <math.h>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -86,55 +87,61 @@ enum TweenType
|
|||
class TweenFunction
|
||||
{
|
||||
public:
|
||||
TweenFunction(float rate);
|
||||
TweenFunction();
|
||||
|
||||
static float tweenTo(float time, TweenType type, float *easingParam);
|
||||
float tweenTo(float time, TweenType type, float *easingParam);
|
||||
|
||||
static float linear(float time);
|
||||
float linear(float time);
|
||||
|
||||
//tween functions for CCActionEase
|
||||
static float easeIn(float time);
|
||||
float easeIn(float time) const;
|
||||
|
||||
static float sineEaseIn(float time);
|
||||
static float sineEaseOut(float time);
|
||||
static float sineEaseInOut(float time);
|
||||
float sineEaseIn(float time);
|
||||
float sineEaseOut(float time);
|
||||
float sineEaseInOut(float time);
|
||||
|
||||
static float quadEaseIn(float time);
|
||||
static float quadEaseOut(float time);
|
||||
static float quadEaseInOut(float time);
|
||||
float quadEaseIn(float time);
|
||||
float quadEaseOut(float time);
|
||||
float quadEaseInOut(float time);
|
||||
|
||||
static float cubicEaseIn(float time);
|
||||
static float cubicEaseOut(float time);
|
||||
static float cubicEaseInOut(float time);
|
||||
float cubicEaseIn(float time);
|
||||
float cubicEaseOut(float time);
|
||||
float cubicEaseInOut(float time);
|
||||
|
||||
static float quartEaseIn(float time);
|
||||
static float quartEaseOut(float time);
|
||||
static float quartEaseInOut(float time);
|
||||
float quartEaseIn(float time);
|
||||
float quartEaseOut(float time);
|
||||
float quartEaseInOut(float time);
|
||||
|
||||
static float quintEaseIn(float time);
|
||||
static float quintEaseOut(float time);
|
||||
static float quintEaseInOut(float time);
|
||||
float quintEaseIn(float time);
|
||||
float quintEaseOut(float time);
|
||||
float quintEaseInOut(float time);
|
||||
|
||||
static float expoEaseIn(float time);
|
||||
static float expoEaseOut(float time);
|
||||
static float expoEaseInOut(float time);
|
||||
float expoEaseIn(float time);
|
||||
float expoEaseOut(float time);
|
||||
float expoEaseInOut(float time);
|
||||
|
||||
static float circEaseIn(float time);
|
||||
static float circEaseOut(float time);
|
||||
static float circEaseInOut(float time);
|
||||
float circEaseIn(float time);
|
||||
float circEaseOut(float time);
|
||||
float circEaseInOut(float time);
|
||||
|
||||
static float elasticEaseIn(float time, float *easingParam);
|
||||
static float elasticEaseOut(float time, float *easingParam);
|
||||
static float elasticEaseInOut(float time, float *easingParam);
|
||||
float elasticEaseIn(float time, float *easingParam);
|
||||
float elasticEaseOut(float time, float *easingParam);
|
||||
float elasticEaseInOut(float time, float *easingParam);
|
||||
|
||||
static float backEaseIn(float time);
|
||||
static float backEaseOut(float time);
|
||||
static float backEaseInOut(float time);
|
||||
float backEaseIn(float time);
|
||||
float backEaseOut(float time);
|
||||
float backEaseInOut(float time);
|
||||
|
||||
static float bounceEaseIn(float time);
|
||||
static float bounceEaseOut(float time);
|
||||
static float bounceEaseInOut(float time);
|
||||
float bounceEaseIn(float time);
|
||||
float bounceEaseOut(float time);
|
||||
float bounceEaseInOut(float time);
|
||||
|
||||
static float customEase(float time, float *easingParam);
|
||||
float customEase(float time, float *easingParam);
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(TweenFunction);
|
||||
float _rate;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -478,7 +478,8 @@ float Tween::updateFrameData(float currentPercent)
|
|||
TweenType tweenType = (_frameTweenEasing != Linear) ? _frameTweenEasing : _tweenEasing;
|
||||
if (tweenType != cocos2d::TWEEN_EASING_MAX && tweenType != Linear && !_passLastFrame)
|
||||
{
|
||||
currentPercent = TweenFunction::tweenTo(currentPercent, tweenType, _from->easingParams);
|
||||
TweenFunction funcObj;
|
||||
currentPercent = funcObj.tweenTo(currentPercent, tweenType, _from->easingParams);
|
||||
}
|
||||
|
||||
return currentPercent;
|
||||
|
|
Loading…
Reference in New Issue