Rest CCFrame.

This commit is contained in:
pipu 2015-04-09 17:21:52 +08:00
parent 80ad7bbee8
commit e86071e77e
2 changed files with 82 additions and 97 deletions

View File

@ -38,17 +38,14 @@ NS_TIMELINE_BEGIN
Frame::Frame()
: _frameIndex(0)
, _tween(true)
, _tweenType(TweenType::Linear)
, _enterWhenPassed(false)
, _timeline(nullptr)
, _node(nullptr)
{
_easingParam.clear();
}
Frame::~Frame()
{
_easingParam.clear();
}
void Frame::emitEvent()
@ -63,37 +60,6 @@ void Frame::cloneProperty(Frame* frame)
{
_frameIndex = frame->getFrameIndex();
_tween = frame->isTween();
_tweenType = frame->getTweenType();
setEasingParams(frame->getEasingParams());
}
void Frame::apply(float percent)
{
if (!_tween)
return;
float tweenpercent = percent;
if ( _tweenType != tweenfunc::TWEEN_EASING_MAX && _tweenType != tweenfunc::Linear)
{
tweenpercent = tweenPercent(tweenpercent);
}
onApply(tweenpercent);
}
float Frame::tweenPercent(float percent)
{
return tweenfunc::tweenTo(percent, _tweenType, _easingParam.data());
}
void Frame::setEasingParams(const std::vector<float>& easingParams)
{
_easingParam.assign(easingParams.begin(), easingParams.end());
}
const std::vector<float>& Frame::getEasingParams() const
{
return _easingParam;
}
@ -117,7 +83,10 @@ VisibleFrame::VisibleFrame()
void VisibleFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
{
if (_node)
{
_node->setVisible(_visible);
}
}
@ -204,6 +173,11 @@ RotationFrame::RotationFrame()
void RotationFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
{
if (_node == nullptr)
{
return;
}
_node->setRotation(_rotation);
if(_tween)
@ -212,9 +186,9 @@ void RotationFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
}
}
void RotationFrame::onApply(float percent)
void RotationFrame::apply(float percent)
{
if (_betwennRotation != 0)
if (_node && _tween && _betwennRotation != 0)
{
float rotation = _rotation + percent * _betwennRotation;
_node->setRotation(rotation);
@ -254,6 +228,11 @@ SkewFrame::SkewFrame()
void SkewFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
{
if (_node == nullptr)
{
return;
}
_node->setSkewX(_skewX);
_node->setSkewY(_skewY);
@ -264,9 +243,9 @@ void SkewFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
}
}
void SkewFrame::onApply(float percent)
void SkewFrame::apply(float percent)
{
if (_betweenSkewX != 0 || _betweenSkewY != 0)
if (_node && _tween && (_betweenSkewX != 0 || _betweenSkewY != 0))
{
float skewx = _skewX + percent * _betweenSkewX;
float skewy = _skewY + percent * _betweenSkewY;
@ -309,6 +288,11 @@ RotationSkewFrame::RotationSkewFrame()
void RotationSkewFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
{
if (_node == nullptr)
{
return;
}
_node->setRotationSkewX(_skewX);
_node->setRotationSkewY(_skewY);
@ -319,9 +303,9 @@ void RotationSkewFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
}
}
void RotationSkewFrame::onApply(float percent)
void RotationSkewFrame::apply(float percent)
{
if (_betweenSkewX != 0 || _betweenSkewY != 0)
if (_node && _tween && (_betweenSkewX != 0 || _betweenSkewY != 0))
{
float skewx = _skewX + percent * _betweenSkewX;
float skewy = _skewY + percent * _betweenSkewY;
@ -363,6 +347,11 @@ PositionFrame::PositionFrame()
void PositionFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
{
if (_node == nullptr)
{
return;
}
_node->setPosition(_position);
if(_tween)
@ -372,9 +361,9 @@ void PositionFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
}
}
void PositionFrame::onApply(float percent)
void PositionFrame::apply(float percent)
{
if (_betweenX != 0 || _betweenY != 0)
if (_node && _tween && (_betweenX != 0 || _betweenY != 0))
{
Point p;
p.x = _position.x + _betweenX * percent;
@ -416,6 +405,11 @@ ScaleFrame::ScaleFrame()
void ScaleFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
{
if (_node == nullptr)
{
return;
}
_node->setScaleX(_scaleX);
_node->setScaleY(_scaleY);
@ -426,9 +420,9 @@ void ScaleFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
}
}
void ScaleFrame::onApply(float percent)
void ScaleFrame::apply(float percent)
{
if (_betweenScaleX != 0 || _betweenScaleY != 0)
if (_node && _tween && (_betweenScaleX != 0 || _betweenScaleY != 0))
{
float scaleX = _scaleX + _betweenScaleX * percent;
float scaleY = _scaleY + _betweenScaleY * percent;
@ -470,6 +464,11 @@ AnchorPointFrame::AnchorPointFrame()
void AnchorPointFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
{
if (_node == nullptr)
{
return;
}
_node->setAnchorPoint(_anchorPoint);
}
@ -506,14 +505,19 @@ InnerActionFrame::InnerActionFrame()
, _startFrameIndex(0)
, _endFrameIndex(0)
, _singleFrameIndex(0)
, _enterWithName(false)
, _animationName("")
, _enterWithName(false)
{
}
void InnerActionFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
{
if (_node == nullptr)
{
return;
}
auto innerActiontimeline = static_cast<ActionTimeline*>(_node->getActionByTag(_node->getTag()));
if( nullptr == innerActiontimeline)
return;
@ -629,20 +633,20 @@ ColorFrame* ColorFrame::create()
}
ColorFrame::ColorFrame()
: _alpha(255)
, _color(Color3B(255, 255, 255))
: _color(Color3B(255, 255, 255))
{
}
void ColorFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
{
_node->setOpacity(_alpha);
if (_node == nullptr)
{
return;
}
_node->setColor(_color);
if(_tween)
{
_betweenAlpha = static_cast<ColorFrame*>(nextFrame)->_alpha - _alpha;
const Color3B& color = static_cast<ColorFrame*>(nextFrame)->_color;
_betweenRed = color.r - _color.r;
_betweenGreen = color.g - _color.g;
@ -650,18 +654,15 @@ void ColorFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
}
}
void ColorFrame::onApply(float percent)
void ColorFrame::apply(float percent)
{
if (_betweenAlpha !=0 || _betweenRed != 0 || _betweenGreen != 0 || _betweenBlue != 0)
if (_node && _tween && (_betweenRed != 0 || _betweenGreen != 0 || _betweenBlue != 0))
{
GLubyte alpha = _alpha + _betweenAlpha * percent;
Color3B color;
color.r = _color.r+ _betweenRed * percent;
color.g = _color.g+ _betweenGreen * percent;
color.b = _color.b+ _betweenBlue * percent;
_node->setOpacity(alpha);
_node->setColor(color);
}
}
@ -669,7 +670,6 @@ void ColorFrame::onApply(float percent)
Frame* ColorFrame::clone()
{
ColorFrame* frame = ColorFrame::create();
frame->setAlpha(_alpha);
frame->setColor(_color);
frame->cloneProperty(this);
@ -697,6 +697,11 @@ AlphaFrame::AlphaFrame()
void AlphaFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
{
if (_node == nullptr)
{
return;
}
_node->setOpacity(_alpha);
if (_tween)
@ -705,10 +710,13 @@ void AlphaFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
}
}
void AlphaFrame::onApply(float percent)
void AlphaFrame::apply(float percent)
{
if (_node && _tween)
{
GLubyte alpha = _alpha + _betweenAlpha * percent;
_node->setOpacity(alpha);
}
}
Frame* AlphaFrame::clone()

View File

@ -30,11 +30,9 @@ THE SOFTWARE.
#include "base/CCVector.h"
#include "2d/CCNode.h"
#include "2d/CCSprite.h"
#include "2d/CCTweenFunction.h"
#include "CCTimelineMacro.h"
#include "cocostudio/CocosStudioExport.h"
using namespace cocos2d::tweenfunc;
NS_TIMELINE_BEGIN
@ -57,26 +55,15 @@ public:
virtual void setTween(bool tween) { _tween = tween; }
virtual bool isTween() const { return _tween; }
virtual void setTweenType(const TweenType& tweenType) { _tweenType = tweenType; }
virtual TweenType getTweenType() const { return _tweenType; }
// !to make easing with params, need setTweenType(TweenType::CUSTOM_EASING)
virtual void setEasingParams(const std::vector<float>& easingParams);
virtual const std::vector<float>& getEasingParams() const;
virtual bool isEnterWhenPassed() { return _enterWhenPassed; }
virtual void onEnter(Frame* nextFrame, int currentFrameIndex) = 0;
virtual void apply(float percent);
virtual void apply(float percent) {}
virtual Frame* clone() = 0;
protected:
Frame();
virtual ~Frame();
virtual void onApply(float percent){}
//update percent depends _tweenType, and return the Calculated percent
virtual float tweenPercent(float percent);
virtual void emitEvent();
virtual void cloneProperty(Frame* frame);
@ -84,15 +71,13 @@ protected:
unsigned int _frameIndex;
bool _tween;
TweenType _tweenType;
std::vector<float> _easingParam;
bool _enterWhenPassed;
Timeline* _timeline;
cocos2d::Node* _node;
};
class CC_STUDIO_DLL VisibleFrame : public Frame
{
public:
@ -118,7 +103,7 @@ public:
TextureFrame();
virtual void setNode(cocos2d::Node* node);
virtual void setNode(cocos2d::Node* node) override;
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
virtual Frame* clone() override;
@ -139,14 +124,13 @@ public:
RotationFrame();
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
virtual void apply(float percent) override;
virtual Frame* clone() override;
inline void setRotation(float rotation) { _rotation = rotation; }
inline float getRotation() const { return _rotation; }
protected:
virtual void onApply(float percent) override;
float _rotation;
float _betwennRotation;
};
@ -159,6 +143,7 @@ public:
SkewFrame();
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
virtual void apply(float percent) override;
virtual Frame* clone() override;
inline void setSkewX(float skewx) { _skewX = skewx; }
@ -168,8 +153,6 @@ public:
inline float getSkewY() const { return _skewY; }
protected:
virtual void onApply(float percent) override;
float _skewX;
float _skewY;
float _betweenSkewX;
@ -185,10 +168,8 @@ public:
RotationSkewFrame();
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
virtual void apply(float percent) override;
virtual Frame* clone() override;
protected:
virtual void onApply(float percent) override;
};
@ -200,6 +181,7 @@ public:
PositionFrame();
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
virtual void apply(float percent) override;
virtual Frame* clone() override;
inline void setPosition(const cocos2d::Point& position) { _position = position; }
@ -211,8 +193,6 @@ public:
inline float getX() const { return _position.x; }
inline float getY() const { return _position.y; }
protected:
virtual void onApply(float percent) override;
cocos2d::Point _position;
float _betweenX;
float _betweenY;
@ -227,6 +207,7 @@ public:
ScaleFrame();
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
virtual void apply(float percent) override;
virtual Frame* clone() override;
inline void setScale(float scale) { _scaleX = scale; _scaleY = scale; }
@ -238,8 +219,6 @@ public:
inline float getScaleY() const { return _scaleY; }
protected:
virtual void onApply(float percent) override;
float _scaleX;
float _scaleY;
float _betweenScaleX;
@ -317,21 +296,20 @@ public:
ColorFrame();
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
virtual void apply(float percent) override;
virtual Frame* clone() override;
inline void setAlpha(GLubyte alpha) { _alpha = alpha; }
inline GLubyte getAlpha() const { return _alpha; }
/** @deprecated Use method setAlpha() and getAlpha() of AlphaFrame instead */
CC_DEPRECATED_ATTRIBUTE inline void setAlpha(GLubyte alpha) { _alpha = alpha; }
CC_DEPRECATED_ATTRIBUTE inline GLubyte getAlpha() const { return _alpha; }
inline void setColor(const cocos2d::Color3B& color) { _color = color; }
inline cocos2d::Color3B getColor() const { return _color; }
protected:
virtual void onApply(float percent) override;
GLubyte _alpha;
cocos2d::Color3B _color;
int _betweenAlpha;
int _betweenRed;
int _betweenGreen;
int _betweenBlue;
@ -344,14 +322,13 @@ public:
AlphaFrame();
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
virtual void apply(float percent) override;
virtual Frame* clone() override;
inline void setAlpha(GLubyte alpha) { _alpha = alpha; }
inline GLubyte getAlpha() const { return _alpha; }
protected:
virtual void onApply(float percent) override;
GLubyte _alpha;
int _betweenAlpha;
};
@ -364,7 +341,7 @@ public:
EventFrame();
virtual void setNode(cocos2d::Node* node);
virtual void setNode(cocos2d::Node* node) override;
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
virtual Frame* clone() override;