refactor easeIn, easeOut and easeInOut, elastic, bounce, back, quartic etc with free tween functions

finish refactor all ease action with tween functions
This commit is contained in:
andyque 2014-02-17 14:44:05 +08:00
parent bcfa32f4e9
commit 6d392766a2
4 changed files with 213 additions and 317 deletions

View File

@ -178,7 +178,7 @@ EaseOut* EaseOut::clone() const
void EaseOut::update(float time) void EaseOut::update(float time)
{ {
_inner->update(powf(time, 1 / _rate)); _inner->update(tweenfunc::easeOut(time, _rate));
} }
EaseOut* EaseOut::reverse() const EaseOut* EaseOut::reverse() const
@ -218,15 +218,7 @@ EaseInOut* EaseInOut::clone() const
void EaseInOut::update(float time) void EaseInOut::update(float time)
{ {
time *= 2; _inner->update(tweenfunc::easeInOut(time, _rate));
if (time < 1)
{
_inner->update(0.5f * powf(time, _rate));
}
else
{
_inner->update(1.0f - 0.5f * powf(2-time, _rate));
}
} }
// InOut and OutIn are symmetrical // InOut and OutIn are symmetrical
@ -267,7 +259,7 @@ EaseExponentialIn* EaseExponentialIn::clone() const
void EaseExponentialIn::update(float time) void EaseExponentialIn::update(float time)
{ {
_inner->update(time == 0 ? 0 : powf(2, 10 * (time/1 - 1)) - 1 * 0.001f); _inner->update(tweenfunc::expoEaseIn(time));
} }
ActionEase * EaseExponentialIn::reverse() const ActionEase * EaseExponentialIn::reverse() const
@ -307,7 +299,7 @@ EaseExponentialOut* EaseExponentialOut::clone() const
void EaseExponentialOut::update(float time) void EaseExponentialOut::update(float time)
{ {
_inner->update(time == 1 ? 1 : (-powf(2, -10 * time / 1) + 1)); _inner->update(tweenfunc::expoEaseOut(time));
} }
ActionEase* EaseExponentialOut::reverse() const ActionEase* EaseExponentialOut::reverse() const
@ -348,17 +340,7 @@ EaseExponentialInOut* EaseExponentialInOut::clone() const
void EaseExponentialInOut::update(float time) void EaseExponentialInOut::update(float time)
{ {
time /= 0.5f; _inner->update(tweenfunc::expoEaseInOut(time));
if (time < 1)
{
time = 0.5f * powf(2, 10 * (time - 1));
}
else
{
time = 0.5f * (-powf(2, -10 * (time - 1)) + 2);
}
_inner->update(time);
} }
EaseExponentialInOut* EaseExponentialInOut::reverse() const EaseExponentialInOut* EaseExponentialInOut::reverse() const
@ -399,7 +381,7 @@ EaseSineIn* EaseSineIn::clone() const
void EaseSineIn::update(float time) void EaseSineIn::update(float time)
{ {
_inner->update(-1 * cosf(time * (float)M_PI_2) + 1); _inner->update(tweenfunc::sineEaseIn(time));
} }
ActionEase* EaseSineIn::reverse() const ActionEase* EaseSineIn::reverse() const
@ -440,7 +422,7 @@ EaseSineOut* EaseSineOut::clone() const
void EaseSineOut::update(float time) void EaseSineOut::update(float time)
{ {
_inner->update(sinf(time * (float)M_PI_2)); _inner->update(tweenfunc::sineEaseOut(time));
} }
ActionEase* EaseSineOut::reverse(void) const ActionEase* EaseSineOut::reverse(void) const
@ -481,7 +463,7 @@ EaseSineInOut* EaseSineInOut::clone() const
void EaseSineInOut::update(float time) void EaseSineInOut::update(float time)
{ {
_inner->update(-0.5f * (cosf((float)M_PI * time) - 1)); _inner->update(tweenfunc::sineEaseInOut(time));
} }
EaseSineInOut* EaseSineInOut::reverse() const EaseSineInOut* EaseSineInOut::reverse() const
@ -542,19 +524,7 @@ EaseElasticIn* EaseElasticIn::clone() const
void EaseElasticIn::update(float time) void EaseElasticIn::update(float time)
{ {
float newT = 0; _inner->update(tweenfunc::elasticEaseIn(time, NULL));
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);
} }
EaseElastic* EaseElasticIn::reverse() const EaseElastic* EaseElasticIn::reverse() const
@ -600,18 +570,7 @@ EaseElasticOut* EaseElasticOut::clone() const
void EaseElasticOut::update(float time) void EaseElasticOut::update(float time)
{ {
float newT = 0; _inner->update(tweenfunc::elasticEaseOut(time, NULL));
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;
}
_inner->update(newT);
} }
EaseElastic* EaseElasticOut::reverse() const EaseElastic* EaseElasticOut::reverse() const
@ -657,33 +616,7 @@ EaseElasticInOut* EaseElasticInOut::clone() const
void EaseElasticInOut::update(float time) void EaseElasticInOut::update(float time)
{ {
float newT = 0; _inner->update(tweenfunc::elasticEaseInOut(time, NULL));
if (time == 0 || time == 1)
{
newT = time;
}
else
{
time = time * 2;
if ( _period == 0)
{
_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);
} }
EaseElasticInOut* EaseElasticInOut::reverse() const EaseElasticInOut* EaseElasticInOut::reverse() const
@ -695,27 +628,6 @@ EaseElasticInOut* EaseElasticInOut::reverse() const
// EaseBounce // EaseBounce
// //
float EaseBounce::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 // EaseBounceIn
// //
@ -749,8 +661,7 @@ EaseBounceIn* EaseBounceIn::clone() const
void EaseBounceIn::update(float time) void EaseBounceIn::update(float time)
{ {
float newT = 1 - bounceTime(1 - time); _inner->update(tweenfunc::bounceEaseIn(time));
_inner->update(newT);
} }
EaseBounce* EaseBounceIn::reverse() const EaseBounce* EaseBounceIn::reverse() const
@ -791,8 +702,7 @@ EaseBounceOut* EaseBounceOut::clone() const
void EaseBounceOut::update(float time) void EaseBounceOut::update(float time)
{ {
float newT = bounceTime(time); _inner->update(tweenfunc::bounceEaseOut(time));
_inner->update(newT);
} }
EaseBounce* EaseBounceOut::reverse() const EaseBounce* EaseBounceOut::reverse() const
@ -833,18 +743,7 @@ EaseBounceInOut* EaseBounceInOut::clone() const
void EaseBounceInOut::update(float time) void EaseBounceInOut::update(float time)
{ {
float newT = 0; _inner->update(tweenfunc::bounceEaseInOut(time));
if (time < 0.5f)
{
time = time * 2;
newT = (1 - bounceTime(1 - time)) * 0.5f;
}
else
{
newT = bounceTime(time * 2 - 1) * 0.5f + 0.5f;
}
_inner->update(newT);
} }
EaseBounceInOut* EaseBounceInOut::reverse() const EaseBounceInOut* EaseBounceInOut::reverse() const
@ -885,8 +784,7 @@ EaseBackIn* EaseBackIn::clone() const
void EaseBackIn::update(float time) void EaseBackIn::update(float time)
{ {
float overshoot = 1.70158f; _inner->update(tweenfunc::backEaseIn(time));
_inner->update(time * time * ((overshoot + 1) * time - overshoot));
} }
ActionEase* EaseBackIn::reverse() const ActionEase* EaseBackIn::reverse() const
@ -927,10 +825,7 @@ EaseBackOut* EaseBackOut::clone() const
void EaseBackOut::update(float time) void EaseBackOut::update(float time)
{ {
float overshoot = 1.70158f; _inner->update(tweenfunc::backEaseOut(time));
time = time - 1;
_inner->update(time * time * ((overshoot + 1) * time + overshoot) + 1);
} }
ActionEase* EaseBackOut::reverse() const ActionEase* EaseBackOut::reverse() const
@ -971,18 +866,7 @@ EaseBackInOut* EaseBackInOut::clone() const
void EaseBackInOut::update(float time) void EaseBackInOut::update(float time)
{ {
float overshoot = 1.70158f * 1.525f; _inner->update(tweenfunc::backEaseInOut(time));
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);
}
} }
EaseBackInOut* EaseBackInOut::reverse() const EaseBackInOut* EaseBackInOut::reverse() const
@ -991,10 +875,7 @@ EaseBackInOut* EaseBackInOut::reverse() const
} }
static inline float bezieratFunction( float a, float b, float c, float d, float t )
{
return (powf(1-t,3) * a + 3*t*(powf(1-t,2))*b + 3*powf(t,2)*(1-t)*c + powf(t,3)*d );
}
EaseBezierAction* EaseBezierAction::create(cocos2d::ActionInterval* action) EaseBezierAction* EaseBezierAction::create(cocos2d::ActionInterval* action)
{ {
@ -1034,7 +915,7 @@ EaseBezierAction* EaseBezierAction::clone() const
void EaseBezierAction::update(float time) void EaseBezierAction::update(float time)
{ {
_inner->update(bezieratFunction(_p0,_p1,_p2,_p3,time)); _inner->update(tweenfunc::bezieratFunction(_p0,_p1,_p2,_p3,time));
} }
EaseBezierAction* EaseBezierAction::reverse() const EaseBezierAction* EaseBezierAction::reverse() const
@ -1074,9 +955,10 @@ EaseQuadraticActionIn* EaseQuadraticActionIn::clone() const
a->autorelease(); a->autorelease();
return a; return a;
} }
void EaseQuadraticActionIn::update(float time) void EaseQuadraticActionIn::update(float time)
{ {
_inner->update(powf(time,2)); _inner->update(tweenfunc::quadraticIn(time));
} }
EaseQuadraticActionIn* EaseQuadraticActionIn::reverse() const EaseQuadraticActionIn* EaseQuadraticActionIn::reverse() const
@ -1117,7 +999,7 @@ EaseQuadraticActionOut* EaseQuadraticActionOut::clone() const
void EaseQuadraticActionOut::update(float time) void EaseQuadraticActionOut::update(float time)
{ {
_inner->update(-time*(time-2)); _inner->update(tweenfunc::quadraticOut(time));
} }
EaseQuadraticActionOut* EaseQuadraticActionOut::reverse() const EaseQuadraticActionOut* EaseQuadraticActionOut::reverse() const
@ -1158,19 +1040,7 @@ EaseQuadraticActionInOut* EaseQuadraticActionInOut::clone() const
void EaseQuadraticActionInOut::update(float time) void EaseQuadraticActionInOut::update(float time)
{ {
float resultTime = time; _inner->update(tweenfunc::quadraticInOut(time));
time = time*2;
if (time < 1)
{
resultTime = time * time * 0.5f;
}
else
{
--time;
resultTime = -0.5f * (time * (time - 2) - 1);
}
_inner->update(resultTime);
} }
EaseQuadraticActionInOut* EaseQuadraticActionInOut::reverse() const EaseQuadraticActionInOut* EaseQuadraticActionInOut::reverse() const
@ -1211,7 +1081,7 @@ EaseQuarticActionIn* EaseQuarticActionIn::clone() const
void EaseQuarticActionIn::update(float time) void EaseQuarticActionIn::update(float time)
{ {
_inner->update(powf(time,4.0f)); _inner->update(tweenfunc::quartEaseIn(time));
} }
EaseQuarticActionIn* EaseQuarticActionIn::reverse() const EaseQuarticActionIn* EaseQuarticActionIn::reverse() const
@ -1252,8 +1122,7 @@ EaseQuarticActionOut* EaseQuarticActionOut::clone() const
void EaseQuarticActionOut::update(float time) void EaseQuarticActionOut::update(float time)
{ {
float tempTime = time -1; _inner->update(tweenfunc::quartEaseOut(time));
_inner->update(1- powf(tempTime,4.0f));
} }
EaseQuarticActionOut* EaseQuarticActionOut::reverse() const EaseQuarticActionOut* EaseQuarticActionOut::reverse() const
@ -1294,16 +1163,7 @@ EaseQuarticActionInOut* EaseQuarticActionInOut::clone() const
void EaseQuarticActionInOut::update(float time) void EaseQuarticActionInOut::update(float time)
{ {
float tempTime = time * 2; _inner->update(tweenfunc::quartEaseInOut(time));
if (tempTime < 1)
tempTime = powf(tempTime,4.0f) * 0.5f;
else
{
tempTime -= 2;
tempTime = 1 - powf(tempTime,4.0f)* 0.5f;
}
_inner->update(tempTime);
} }
EaseQuarticActionInOut* EaseQuarticActionInOut::reverse() const EaseQuarticActionInOut* EaseQuarticActionInOut::reverse() const
@ -1344,7 +1204,7 @@ EaseQuinticActionIn* EaseQuinticActionIn::clone() const
void EaseQuinticActionIn::update(float time) void EaseQuinticActionIn::update(float time)
{ {
_inner->update(powf(time,5.0f)); _inner->update(tweenfunc::quintEaseIn(time));
} }
EaseQuinticActionIn* EaseQuinticActionIn::reverse() const EaseQuinticActionIn* EaseQuinticActionIn::reverse() const
@ -1385,8 +1245,7 @@ EaseQuinticActionOut* EaseQuinticActionOut::clone() const
void EaseQuinticActionOut::update(float time) void EaseQuinticActionOut::update(float time)
{ {
float tempTime = time -1; _inner->update(tweenfunc::quintEaseOut(time));
_inner->update(1 + powf(tempTime,5.0f));
} }
EaseQuinticActionOut* EaseQuinticActionOut::reverse() const EaseQuinticActionOut* EaseQuinticActionOut::reverse() const
@ -1427,16 +1286,7 @@ EaseQuinticActionInOut* EaseQuinticActionInOut::clone() const
void EaseQuinticActionInOut::update(float time) void EaseQuinticActionInOut::update(float time)
{ {
float tempTime = time * 2; _inner->update(tweenfunc::quintEaseInOut(time));
if (tempTime < 1)
tempTime = powf(tempTime,5.0f) * 0.5f;
else
{
tempTime -= 2;
tempTime = 1 + powf(tempTime,5.0f)* 0.5f;
}
_inner->update(tempTime);
} }
EaseQuinticActionInOut* EaseQuinticActionInOut::reverse() const EaseQuinticActionInOut* EaseQuinticActionInOut::reverse() const
@ -1477,7 +1327,7 @@ EaseCircleActionIn* EaseCircleActionIn::clone() const
void EaseCircleActionIn::update(float time) void EaseCircleActionIn::update(float time)
{ {
_inner->update(1-sqrt(1-powf(time,2.0f))); _inner->update(tweenfunc::circEaseIn(time));
} }
EaseCircleActionIn* EaseCircleActionIn::reverse() const EaseCircleActionIn* EaseCircleActionIn::reverse() const
@ -1518,8 +1368,7 @@ EaseCircleActionOut* EaseCircleActionOut::clone() const
void EaseCircleActionOut::update(float time) void EaseCircleActionOut::update(float time)
{ {
float tempTime = time - 1; _inner->update(tweenfunc::circEaseOut(time));
_inner->update(sqrt(1-powf(tempTime,2.0f)));
} }
EaseCircleActionOut* EaseCircleActionOut::reverse() const EaseCircleActionOut* EaseCircleActionOut::reverse() const
@ -1560,16 +1409,7 @@ EaseCircleActionInOut* EaseCircleActionInOut::clone() const
void EaseCircleActionInOut::update(float time) void EaseCircleActionInOut::update(float time)
{ {
float tempTime = time * 2; _inner->update(tweenfunc::circEaseInOut(time));
if (tempTime < 1)
tempTime = (1- sqrt(1 - powf(tempTime,2.0f))) * 0.5f;
else
{
tempTime -= 2;
tempTime = (1+ sqrt(1 - powf(tempTime,2.0f))) * 0.5f;
}
_inner->update(time);
} }
EaseCircleActionInOut* EaseCircleActionInOut::reverse() const EaseCircleActionInOut* EaseCircleActionInOut::reverse() const
@ -1610,7 +1450,7 @@ EaseCubicActionIn* EaseCubicActionIn::clone() const
void EaseCubicActionIn::update(float time) void EaseCubicActionIn::update(float time)
{ {
_inner->update(powf(time,3.0f)); _inner->update(tweenfunc::cubicEaseIn(time));
} }
EaseCubicActionIn* EaseCubicActionIn::reverse() const EaseCubicActionIn* EaseCubicActionIn::reverse() const
@ -1651,8 +1491,7 @@ EaseCubicActionOut* EaseCubicActionOut::clone() const
void EaseCubicActionOut::update(float time) void EaseCubicActionOut::update(float time)
{ {
time -= 1; _inner->update(tweenfunc::cubicEaseOut(time));
_inner->update(1+powf(time,3.0f));
} }
EaseCubicActionOut* EaseCubicActionOut::reverse() const EaseCubicActionOut* EaseCubicActionOut::reverse() const
@ -1693,15 +1532,7 @@ EaseCubicActionInOut* EaseCubicActionInOut::clone() const
void EaseCubicActionInOut::update(float time) void EaseCubicActionInOut::update(float time)
{ {
float tempTime = time * 2; _inner->update(tweenfunc::cubicEaseInOut(time));
if (tempTime < 1)
tempTime = powf(tempTime,3.0f) * 0.5f;
else
{
tempTime -= 2;
tempTime = 1 + powf(tempTime,3.0f)* 0.5f;
}
_inner->update(time);
} }
EaseCubicActionInOut* EaseCubicActionInOut::reverse() const EaseCubicActionInOut* EaseCubicActionInOut::reverse() const

View File

@ -425,7 +425,6 @@ private:
class CC_DLL EaseBounce : public ActionEase class CC_DLL EaseBounce : public ActionEase
{ {
public: public:
float bounceTime(float time);
// Overrides // Overrides
virtual EaseBounce* clone() const override = 0; virtual EaseBounce* clone() const override = 0;

View File

@ -42,118 +42,118 @@ float tweenTo(float time, TweenType type, float *easingParam)
switch (type) switch (type)
{ {
case CUSTOM_EASING: case CUSTOM_EASING:
delta = customEase(time, easingParam); delta = customEase(time, easingParam);
break; break;
case Linear: case Linear:
delta = linear(time); delta = linear(time);
break; break;
case Sine_EaseIn: case Sine_EaseIn:
delta = sineEaseIn(time); delta = sineEaseIn(time);
break; break;
case Sine_EaseOut: case Sine_EaseOut:
delta = sineEaseOut(time); delta = sineEaseOut(time);
break; break;
case Sine_EaseInOut: case Sine_EaseInOut:
delta = sineEaseInOut(time); delta = sineEaseInOut(time);
break; break;
case Quad_EaseIn: case Quad_EaseIn:
delta = quadEaseIn(time); delta = quadEaseIn(time);
break; break;
case Quad_EaseOut: case Quad_EaseOut:
delta = quadEaseOut(time); delta = quadEaseOut(time);
break; break;
case Quad_EaseInOut: case Quad_EaseInOut:
delta = quadEaseInOut(time); delta = quadEaseInOut(time);
break; break;
case Cubic_EaseIn: case Cubic_EaseIn:
delta = cubicEaseIn(time); delta = cubicEaseIn(time);
break; break;
case Cubic_EaseOut: case Cubic_EaseOut:
delta = cubicEaseOut(time); delta = cubicEaseOut(time);
break; break;
case Cubic_EaseInOut: case Cubic_EaseInOut:
delta = cubicEaseInOut(time); delta = cubicEaseInOut(time);
break; break;
case Quart_EaseIn: case Quart_EaseIn:
delta = quartEaseIn(time); delta = quartEaseIn(time);
break; break;
case Quart_EaseOut: case Quart_EaseOut:
delta = quartEaseOut(time); delta = quartEaseOut(time);
break; break;
case Quart_EaseInOut: case Quart_EaseInOut:
delta = quartEaseInOut(time); delta = quartEaseInOut(time);
break; break;
case Quint_EaseIn: case Quint_EaseIn:
delta = quintEaseIn(time); delta = quintEaseIn(time);
break; break;
case Quint_EaseOut: case Quint_EaseOut:
delta = quintEaseOut(time); delta = quintEaseOut(time);
break; break;
case Quint_EaseInOut: case Quint_EaseInOut:
delta = quintEaseInOut(time); delta = quintEaseInOut(time);
break; break;
case Expo_EaseIn: case Expo_EaseIn:
delta = expoEaseIn(time); delta = expoEaseIn(time);
break; break;
case Expo_EaseOut: case Expo_EaseOut:
delta = expoEaseOut(time); delta = expoEaseOut(time);
break; break;
case Expo_EaseInOut: case Expo_EaseInOut:
delta = expoEaseInOut(time); delta = expoEaseInOut(time);
break; break;
case Circ_EaseIn: case Circ_EaseIn:
delta = circEaseIn(time); delta = circEaseIn(time);
break; break;
case Circ_EaseOut: case Circ_EaseOut:
delta = circEaseOut(time); delta = circEaseOut(time);
break; break;
case Circ_EaseInOut: case Circ_EaseInOut:
delta = circEaseInOut(time); delta = circEaseInOut(time);
break; break;
case Elastic_EaseIn: case Elastic_EaseIn:
delta = elasticEaseIn(time, easingParam); delta = elasticEaseIn(time, easingParam);
break; break;
case Elastic_EaseOut: case Elastic_EaseOut:
delta = elasticEaseOut(time, easingParam); delta = elasticEaseOut(time, easingParam);
break; break;
case Elastic_EaseInOut: case Elastic_EaseInOut:
delta = elasticEaseInOut(time, easingParam); delta = elasticEaseInOut(time, easingParam);
break; break;
case Back_EaseIn: case Back_EaseIn:
delta = backEaseIn(time); delta = backEaseIn(time);
break; break;
case Back_EaseOut: case Back_EaseOut:
delta = backEaseOut(time); delta = backEaseOut(time);
break; break;
case Back_EaseInOut: case Back_EaseInOut:
delta = backEaseInOut(time); delta = backEaseInOut(time);
break; break;
case Bounce_EaseIn: case Bounce_EaseIn:
delta = bounceEaseIn(time); delta = bounceEaseIn(time);
break; break;
case Bounce_EaseOut: case Bounce_EaseOut:
delta = bounceEaseOut(time); delta = bounceEaseOut(time);
break; break;
case Bounce_EaseInOut: case Bounce_EaseInOut:
delta = bounceEaseInOut(time); delta = bounceEaseInOut(time);
break; break;
default: default:
delta = sineEaseInOut(time); delta = sineEaseInOut(time);
break; break;
} }
return delta; return delta;
@ -171,10 +171,12 @@ float sineEaseIn(float time)
{ {
return -1 * cosf(time * (float)M_PI_2) + 1; return -1 * cosf(time * (float)M_PI_2) + 1;
} }
float sineEaseOut(float time) float sineEaseOut(float time)
{ {
return sinf(time * (float)M_PI_2); return sinf(time * (float)M_PI_2);
} }
float sineEaseInOut(float time) float sineEaseInOut(float time)
{ {
return -0.5f * (cosf((float)M_PI * time) - 1); return -0.5f * (cosf((float)M_PI * time) - 1);
@ -186,10 +188,12 @@ float quadEaseIn(float time)
{ {
return time * time; return time * time;
} }
float quadEaseOut(float time) float quadEaseOut(float time)
{ {
return -1 * time * (time - 2); return -1 * time * (time - 2);
} }
float quadEaseInOut(float time) float quadEaseInOut(float time)
{ {
time = time*2; time = time*2;
@ -226,11 +230,13 @@ float quartEaseIn(float time)
{ {
return time * time * time * time; return time * time * time * time;
} }
float quartEaseOut(float time) float quartEaseOut(float time)
{ {
time -= 1; time -= 1;
return -(time * time * time * time - 1); return -(time * time * time * time - 1);
} }
float quartEaseInOut(float time) float quartEaseInOut(float time)
{ {
time = time*2; time = time*2;
@ -246,11 +252,13 @@ float quintEaseIn(float time)
{ {
return time * time * time * time * time; return time * time * time * time * time;
} }
float quintEaseOut(float time) float quintEaseOut(float time)
{ {
time -=1; time -=1;
return (time * time * time * time * time + 1); return (time * time * time * time * time + 1);
} }
float quintEaseInOut(float time) float quintEaseInOut(float time)
{ {
time = time*2; time = time*2;
@ -485,6 +493,56 @@ float easeIn(float time, float rate)
return powf(time, rate); return powf(time, rate);
} }
float easeOut(float time, float rate)
{
return powf(time, 1 / rate);
}
float easeInOut(float time, float rate)
{
time *= 2;
if (time < 1)
{
return 0.5f * powf(time, rate);
}
else
{
return (1.0f - 0.5f * powf(2 - time, rate));
}
}
float quadraticIn(float time)
{
return powf(time,2);
}
float quadraticOut(float time)
{
return -time*(time-2);
}
float quadraticInOut(float time)
{
float resultTime = time;
time = time*2;
if (time < 1)
{
resultTime = time * time * 0.5f;
}
else
{
--time;
resultTime = -0.5f * (time * (time - 2) - 1);
}
return resultTime;
}
float bezieratFunction( float a, float b, float c, float d, float t )
{
return (powf(1-t,3) * a + 3*t*(powf(1-t,2))*b + 3*powf(t,2)*(1-t)*c + powf(t,3)*d );
}
} }
NS_CC_END NS_CC_END

View File

@ -85,6 +85,14 @@ namespace tweenfunc {
//tween functions for CCActionEase //tween functions for CCActionEase
float easeIn(float time, float rate); float easeIn(float time, float rate);
float easeOut(float time, float rate);
float easeInOut(float time, float rate);
float bezieratFunction( float a, float b, float c, float d, float t );
float quadraticIn(float time);
float quadraticOut(float time);
float quadraticInOut(float time);
float tweenTo(float time, TweenType type, float *easingParam); float tweenTo(float time, TweenType type, float *easingParam);