change CCTweenFunction class to tweenfunc namespace

This commit is contained in:
andyque 2014-02-17 14:30:17 +08:00
parent 838c71b135
commit 68b1c9f2c1
12 changed files with 132 additions and 156 deletions

View File

@ -138,9 +138,7 @@ EaseIn* EaseIn::clone() const
void EaseIn::update(float time)
{
TweenFunction funObj(_rate);
_tweenFunction = &TweenFunction::easeIn;
_inner->update(_tweenFunction(funObj,time));
_inner->update(tweenfunc::easeIn(time, _rate));
}
EaseIn* EaseIn::reverse() const

View File

@ -26,24 +26,17 @@ THE SOFTWARE.
NS_CC_BEGIN
namespace tweenfunc {
#ifndef M_PI_X_2
#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)
float tweenTo(float time, TweenType type, float *easingParam)
{
float delta = 0;
@ -167,37 +160,37 @@ float TweenFunction::tweenTo(float time, TweenType type, float *easingParam)
}
// Linear
float TweenFunction::linear(float time)
float linear(float time)
{
return time;
}
// Sine Ease
float TweenFunction::sineEaseIn(float time)
float sineEaseIn(float time)
{
return -1 * cosf(time * (float)M_PI_2) + 1;
}
float TweenFunction::sineEaseOut(float time)
float sineEaseOut(float time)
{
return sinf(time * (float)M_PI_2);
}
float TweenFunction::sineEaseInOut(float time)
float sineEaseInOut(float time)
{
return -0.5f * (cosf((float)M_PI * time) - 1);
}
// Quad Ease
float TweenFunction::quadEaseIn(float time)
float quadEaseIn(float time)
{
return time * time;
}
float TweenFunction::quadEaseOut(float time)
float quadEaseOut(float time)
{
return -1 * time * (time - 2);
}
float TweenFunction::quadEaseInOut(float time)
float quadEaseInOut(float time)
{
time = time*2;
if (time < 1)
@ -209,16 +202,16 @@ float TweenFunction::quadEaseInOut(float time)
// Cubic Ease
float TweenFunction::cubicEaseIn(float time)
float cubicEaseIn(float time)
{
return time * time * time;
}
float TweenFunction::cubicEaseOut(float time)
float cubicEaseOut(float time)
{
time -= 1;
return (time * time * time + 1);
}
float TweenFunction::cubicEaseInOut(float time)
float cubicEaseInOut(float time)
{
time = time*2;
if (time < 1)
@ -229,16 +222,16 @@ float TweenFunction::cubicEaseInOut(float time)
// Quart Ease
float TweenFunction::quartEaseIn(float time)
float quartEaseIn(float time)
{
return time * time * time * time;
}
float TweenFunction::quartEaseOut(float time)
float quartEaseOut(float time)
{
time -= 1;
return -(time * time * time * time - 1);
}
float TweenFunction::quartEaseInOut(float time)
float quartEaseInOut(float time)
{
time = time*2;
if (time < 1)
@ -249,16 +242,16 @@ float TweenFunction::quartEaseInOut(float time)
// Quint Ease
float TweenFunction::quintEaseIn(float time)
float quintEaseIn(float time)
{
return time * time * time * time * time;
}
float TweenFunction::quintEaseOut(float time)
float quintEaseOut(float time)
{
time -=1;
return (time * time * time * time * time + 1);
}
float TweenFunction::quintEaseInOut(float time)
float quintEaseInOut(float time)
{
time = time*2;
if (time < 1)
@ -269,15 +262,15 @@ float TweenFunction::quintEaseInOut(float time)
// Expo Ease
float TweenFunction::expoEaseIn(float time)
float expoEaseIn(float time)
{
return time == 0 ? 0 : powf(2, 10 * (time/1 - 1)) - 1 * 0.001f;
}
float TweenFunction::expoEaseOut(float time)
float expoEaseOut(float time)
{
return time == 1 ? 1 : (-powf(2, -10 * time / 1) + 1);
}
float TweenFunction::expoEaseInOut(float time)
float expoEaseInOut(float time)
{
time /= 0.5f;
if (time < 1)
@ -294,16 +287,16 @@ float TweenFunction::expoEaseInOut(float time)
// Circ Ease
float TweenFunction::circEaseIn(float time)
float circEaseIn(float time)
{
return -1 * (sqrt(1 - time * time) - 1);
}
float TweenFunction::circEaseOut(float time)
float circEaseOut(float time)
{
time = time - 1;
return sqrt(1 - time * time);
}
float TweenFunction::circEaseInOut(float time)
float circEaseInOut(float time)
{
time = time * 2;
if (time < 1)
@ -314,7 +307,7 @@ float TweenFunction::circEaseInOut(float time)
// Elastic Ease
float TweenFunction::elasticEaseIn(float time, float *easingParam)
float elasticEaseIn(float time, float *easingParam)
{
float period = 0.3f;
@ -337,7 +330,7 @@ float TweenFunction::elasticEaseIn(float time, float *easingParam)
return newT;
}
float TweenFunction::elasticEaseOut(float time, float *easingParam)
float elasticEaseOut(float time, float *easingParam)
{
float period = 0.3f;
@ -359,7 +352,7 @@ float TweenFunction::elasticEaseOut(float time, float *easingParam)
return newT;
}
float TweenFunction::elasticEaseInOut(float time, float *easingParam)
float elasticEaseInOut(float time, float *easingParam)
{
float period = 0.3f;
@ -398,19 +391,19 @@ float TweenFunction::elasticEaseInOut(float time, float *easingParam)
// Back Ease
float TweenFunction::backEaseIn(float time)
float backEaseIn(float time)
{
float overshoot = 1.70158f;
return time * time * ((overshoot + 1) * time - overshoot);
}
float TweenFunction::backEaseOut(float time)
float backEaseOut(float time)
{
float overshoot = 1.70158f;
time = time - 1;
return time * time * ((overshoot + 1) * time + overshoot) + 1;
}
float TweenFunction::backEaseInOut(float time)
float backEaseInOut(float time)
{
float overshoot = 1.70158f * 1.525f;
@ -434,32 +427,32 @@ float 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;
}
}
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;
time -= 2.625f / 2.75f;
return 7.5625f * time * time + 0.984375f;
}
float TweenFunction::bounceEaseIn(float time)
float bounceEaseIn(float time)
{
return 1 - bounceTime(1 - time);
}
float TweenFunction::bounceEaseOut(float time)
float bounceEaseOut(float time)
{
return bounceTime(time);
}
float TweenFunction::bounceEaseInOut(float time)
float bounceEaseInOut(float time)
{
float newT = 0;
if (time < 0.5f)
@ -477,7 +470,7 @@ float TweenFunction::bounceEaseInOut(float time)
// Custom Ease
float TweenFunction::customEase(float time, float *easingParam)
float customEase(float time, float *easingParam)
{
if (easingParam)
{
@ -487,10 +480,11 @@ float TweenFunction::customEase(float time, float *easingParam)
return time;
}
float TweenFunction::easeIn(float time) const
float easeIn(float time, float rate)
{
return powf(time, _rate);
return powf(time, rate);
}
}
NS_CC_END

View File

@ -31,71 +31,66 @@ THE SOFTWARE.
NS_CC_BEGIN
enum TweenType
{
CUSTOM_EASING = -1,
Linear,
Sine_EaseIn,
Sine_EaseOut,
Sine_EaseInOut,
Quad_EaseIn,
Quad_EaseOut,
Quad_EaseInOut,
Cubic_EaseIn,
Cubic_EaseOut,
Cubic_EaseInOut,
Quart_EaseIn,
Quart_EaseOut,
Quart_EaseInOut,
Quint_EaseIn,
Quint_EaseOut,
Quint_EaseInOut,
Expo_EaseIn,
Expo_EaseOut,
Expo_EaseInOut,
Circ_EaseIn,
Circ_EaseOut,
Circ_EaseInOut,
Elastic_EaseIn,
Elastic_EaseOut,
Elastic_EaseInOut,
Back_EaseIn,
Back_EaseOut,
Back_EaseInOut,
Bounce_EaseIn,
Bounce_EaseOut,
Bounce_EaseInOut,
TWEEN_EASING_MAX = 10000
};
/**
* @js NA
* @lua NA
*/
class TweenFunction
{
public:
TweenFunction(float rate);
TweenFunction();
namespace tweenfunc {
enum TweenType
{
CUSTOM_EASING = -1,
Linear,
Sine_EaseIn,
Sine_EaseOut,
Sine_EaseInOut,
Quad_EaseIn,
Quad_EaseOut,
Quad_EaseInOut,
Cubic_EaseIn,
Cubic_EaseOut,
Cubic_EaseInOut,
Quart_EaseIn,
Quart_EaseOut,
Quart_EaseInOut,
Quint_EaseIn,
Quint_EaseOut,
Quint_EaseInOut,
Expo_EaseIn,
Expo_EaseOut,
Expo_EaseInOut,
Circ_EaseIn,
Circ_EaseOut,
Circ_EaseInOut,
Elastic_EaseIn,
Elastic_EaseOut,
Elastic_EaseInOut,
Back_EaseIn,
Back_EaseOut,
Back_EaseInOut,
Bounce_EaseIn,
Bounce_EaseOut,
Bounce_EaseInOut,
TWEEN_EASING_MAX = 10000
};
//tween functions for CCActionEase
float easeIn(float time, float rate);
float tweenTo(float time, TweenType type, float *easingParam);
float linear(float time);
//tween functions for CCActionEase
float easeIn(float time) const;
float sineEaseIn(float time);
float sineEaseOut(float time);
@ -138,12 +133,7 @@ public:
float bounceEaseInOut(float time);
float customEase(float time, float *easingParam);
private:
DISALLOW_COPY_AND_ASSIGN(TweenFunction);
float _rate;
};
}
NS_CC_END

View File

@ -59,13 +59,12 @@ CC_DEPRECATED_ATTRIBUTE typedef DisplayManager CCDisplayManager;
CC_DEPRECATED_ATTRIBUTE typedef ColliderBody CCColliderBody;
CC_DEPRECATED_ATTRIBUTE typedef ColliderDetector CCColliderDetector;
CC_DEPRECATED_ATTRIBUTE typedef SpriteFrameCacheHelper CCSpriteFrameCacheHelper;
CC_DEPRECATED_ATTRIBUTE typedef TweenFunction CCTweenFunction;
CC_DEPRECATED_ATTRIBUTE typedef ArmatureData CCArmatureData;
CC_DEPRECATED_ATTRIBUTE typedef Bone CCBone;
CC_DEPRECATED_ATTRIBUTE typedef ArmatureAnimation CCArmatureAnimation;
CC_DEPRECATED_ATTRIBUTE typedef Armature CCArmature;
CC_DEPRECATED_ATTRIBUTE typedef ArmatureDataManager CCArmatureDataManager;
CC_DEPRECATED_ATTRIBUTE typedef TweenType CCTweenType;
CC_DEPRECATED_ATTRIBUTE typedef cocos2d::tweenfunc::TweenType CCTweenType;
class Armature : public cocos2d::Node, public cocos2d::BlendProtocol
{

View File

@ -183,7 +183,7 @@ void ArmatureAnimation::play(const std::string& animationName, int durationTo,
int durationTween = _movementData->durationTween == 0 ? _rawDuration : _movementData->durationTween;
TweenType tweenEasing = _movementData->tweenEasing;
cocos2d::tweenfunc::TweenType tweenEasing = _movementData->tweenEasing;
loop = (loop < 0) ? _movementData->loop : loop;
_onMovementList = false;

View File

@ -743,12 +743,12 @@ MovementData *DataReaderHelper::decodeMovement(tinyxml2::XMLElement *movementXML
{
if( movementXML->QueryIntAttribute(A_TWEEN_EASING, &(tweenEasing)) == tinyxml2::XML_SUCCESS)
{
movementData->tweenEasing = tweenEasing == 2 ? Sine_EaseInOut : (TweenType)tweenEasing;
movementData->tweenEasing = tweenEasing == 2 ? cocos2d::tweenfunc::Sine_EaseInOut : (TweenType)tweenEasing;
}
}
else
{
movementData->tweenEasing = Linear;
movementData->tweenEasing = cocos2d::tweenfunc::Linear;
}
}
@ -1072,12 +1072,12 @@ FrameData *DataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, tinyxm
{
if( frameXML->QueryIntAttribute(A_TWEEN_EASING, &(tweenEasing)) == tinyxml2::XML_SUCCESS)
{
frameData->tweenEasing = tweenEasing == 2 ? Sine_EaseInOut : (TweenType)tweenEasing;
frameData->tweenEasing = tweenEasing == 2 ? cocos2d::tweenfunc::Sine_EaseInOut : (cocos2d::tweenfunc::TweenType)tweenEasing;
}
}
else
{
frameData->tweenEasing = Linear;
frameData->tweenEasing = cocos2d::tweenfunc::Linear;
}
}
@ -1461,7 +1461,7 @@ MovementData *DataReaderHelper::decodeMovement(const rapidjson::Value& json, Dat
{
movementData->scale = DICTOOL->getFloatValue_json(json, A_MOVEMENT_SCALE, 1.0f);
}
movementData->tweenEasing = (TweenType)(DICTOOL->getIntValue_json(json, A_TWEEN_EASING, Linear));
movementData->tweenEasing = (TweenType)(DICTOOL->getIntValue_json(json, A_TWEEN_EASING, cocos2d::tweenfunc::Linear));
const char *name = DICTOOL->getStringValue_json(json, A_NAME);
if(name != nullptr)
@ -1557,7 +1557,7 @@ FrameData *DataReaderHelper::decodeFrame(const rapidjson::Value& json, DataInfo
decodeNode(frameData, json, dataInfo);
frameData->tweenEasing = (TweenType)(DICTOOL->getIntValue_json(json, A_TWEEN_EASING, Linear));
frameData->tweenEasing = (TweenType)(DICTOOL->getIntValue_json(json, A_TWEEN_EASING, cocos2d::tweenfunc::Linear));
frameData->displayIndex = DICTOOL->getIntValue_json(json, A_DISPLAY_INDEX);
frameData->blendFunc.src = (GLenum)(DICTOOL->getIntValue_json(json, A_BLEND_SRC, BlendFunc::ALPHA_NON_PREMULTIPLIED.src));
frameData->blendFunc.dst = (GLenum)(DICTOOL->getIntValue_json(json, A_BLEND_DST, BlendFunc::ALPHA_NON_PREMULTIPLIED.dst));

View File

@ -249,7 +249,7 @@ BoneData *ArmatureData::getBoneData(const std::string& boneName)
FrameData::FrameData(void)
: frameID(0)
, duration(1)
, tweenEasing(Linear)
, tweenEasing(cocos2d::tweenfunc::Linear)
, easingParamNumber(0)
, easingParams(NULL)
, isTween(true)
@ -330,7 +330,7 @@ MovementData::MovementData(void)
, durationTo(0)
, durationTween(0)
, loop(true)
, tweenEasing(Linear)
, tweenEasing(cocos2d::tweenfunc::Linear)
{
}

View File

@ -63,9 +63,6 @@ public: \
namespace cocostudio {
using cocos2d::TweenFunction;
using cocos2d::TweenType;
/**
* The base node include a lot of attributes.
* @js NA
@ -337,7 +334,7 @@ public:
int frameID;
int duration; //! The frame will last duration frames
TweenType tweenEasing; //! Every frame's tween easing effect
cocos2d::tweenfunc::TweenType tweenEasing; //! Every frame's tween easing effect
int easingParamNumber;
float *easingParams;
@ -440,7 +437,7 @@ public:
* Which tween easing effect the movement use
* TWEEN_EASING_MAX : use the value from MovementData get from flash design panel
*/
TweenType tweenEasing;
cocos2d::tweenfunc::TweenType tweenEasing;
/**
* @brief save movment bone data

View File

@ -37,7 +37,7 @@ ProcessBase::ProcessBase(void)
, _currentPercent(0.0f)
, _rawDuration(0)
, _loopType(ANIMATION_LOOP_BACK)
, _tweenEasing(Linear)
, _tweenEasing(cocos2d::tweenfunc::Linear)
, _animationInternal(1/60.0f)
, _durationTween(0)
, _currentFrame(0)
@ -83,7 +83,7 @@ void ProcessBase::play(int durationTo, int durationTween, int loop, int tweenEa
* When changing end, m_iTotalFrames will be setted to _durationTween
*/
_nextFrameIndex = durationTo;
_tweenEasing = (TweenType)tweenEasing;
_tweenEasing = (cocos2d::tweenfunc::TweenType)tweenEasing;
}

View File

@ -30,8 +30,6 @@ THE SOFTWARE.
namespace cocostudio {
using cocos2d::TweenType;
using cocos2d::TweenFunction;
enum AnimationType
{
@ -158,7 +156,7 @@ protected:
AnimationType _loopType;
//! The tween easing effect
TweenType _tweenEasing;
cocos2d::tweenfunc::TweenType _tweenEasing;
//! The animation update speed
float _animationInternal;

View File

@ -33,7 +33,7 @@ THE SOFTWARE.
namespace cocostudio {
using cocos2d::Linear;
using cocos2d::tweenfunc::Linear;
Tween *Tween::create(Bone *bone)
{
@ -282,7 +282,7 @@ void Tween::updateHandler()
percent = updateFrameData(percent);
}
if(_frameTweenEasing != cocos2d::TWEEN_EASING_MAX)
if(_frameTweenEasing != ::cocos2d::tweenfunc::TWEEN_EASING_MAX)
{
tweenNodeTo(percent);
}
@ -476,10 +476,9 @@ float Tween::updateFrameData(float currentPercent)
* If frame tween easing equal to TWEEN_EASING_MAX, then it will not do tween.
*/
TweenType tweenType = (_frameTweenEasing != Linear) ? _frameTweenEasing : _tweenEasing;
if (tweenType != cocos2d::TWEEN_EASING_MAX && tweenType != Linear && !_passLastFrame)
if (tweenType != ::cocos2d::tweenfunc::TWEEN_EASING_MAX && tweenType != Linear && !_passLastFrame)
{
TweenFunction funcObj;
currentPercent = funcObj.tweenTo(currentPercent, tweenType, _from->easingParams);
currentPercent = cocos2d::tweenfunc::tweenTo(currentPercent, tweenType, _from->easingParams);
}
return currentPercent;

View File

@ -33,6 +33,7 @@ namespace cocostudio {
class Bone;
class ArmatureAnimation;
using cocos2d::tweenfunc::TweenType;
/**
* @js NA
@ -132,7 +133,7 @@ protected:
Bone *_bone; //! A weak reference to the Bone
TweenType _frameTweenEasing; //! Dedermine which tween effect current frame use
cocos2d::tweenfunc::TweenType _frameTweenEasing; //! Dedermine which tween effect current frame use
int _betweenDuration; //! Current key frame will last _betweenDuration frames
int _totalDuration;