2013-09-20 22:23:13 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:47:11 +08:00
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
2013-12-26 16:29:59 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
2013-09-20 22:23:13 +08:00
|
|
|
|
|
|
|
#include "CCActionFrame.h"
|
2014-02-17 11:20:01 +08:00
|
|
|
#include "CCActionEase.h"
|
2013-09-20 22:23:13 +08:00
|
|
|
|
2013-12-26 16:29:59 +08:00
|
|
|
using namespace cocos2d;
|
2013-10-15 18:00:03 +08:00
|
|
|
|
|
|
|
namespace cocostudio {
|
2013-09-20 22:23:13 +08:00
|
|
|
|
|
|
|
ActionFrame::ActionFrame()
|
|
|
|
: _frameType(0)
|
|
|
|
, _frameIndex(0)
|
|
|
|
, _fTime(0.0f)
|
2013-12-27 17:21:13 +08:00
|
|
|
, _easingType(FrameEaseType::LINERAR)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
ActionFrame::~ActionFrame()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionFrame::setFrameIndex(int index)
|
|
|
|
{
|
|
|
|
_frameIndex = index;
|
|
|
|
}
|
|
|
|
int ActionFrame::getFrameIndex()
|
|
|
|
{
|
|
|
|
return _frameIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionFrame::setFrameTime(float fTime)
|
|
|
|
{
|
|
|
|
_fTime = fTime;
|
|
|
|
}
|
|
|
|
float ActionFrame::getFrameTime()
|
|
|
|
{
|
|
|
|
return _fTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionFrame::setFrameType(int frameType)
|
|
|
|
{
|
|
|
|
_frameType = frameType;
|
|
|
|
}
|
|
|
|
int ActionFrame::getFrameType()
|
|
|
|
{
|
|
|
|
return _frameType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionFrame::setEasingType(int easingType)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
_easingType = (FrameEaseType)easingType;
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
int ActionFrame::getEasingType()
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
return (int)_easingType;
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
ActionInterval* ActionFrame::getAction(float fDuration)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
|
|
|
log("Need a definition of <getAction> for ActionFrame");
|
2013-12-26 16:29:59 +08:00
|
|
|
return nullptr;
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
ActionInterval* ActionFrame::getAction(float fDuration,ActionFrame* srcFrame)
|
|
|
|
{
|
|
|
|
return this->getAction(fDuration);
|
|
|
|
}
|
|
|
|
|
2013-12-26 23:40:50 +08:00
|
|
|
void ActionFrame::setEasingParameter(std::vector<float>& parameter)
|
2013-12-24 20:33:55 +08:00
|
|
|
{
|
|
|
|
_Parameter.clear();
|
|
|
|
|
2013-12-26 23:40:50 +08:00
|
|
|
for (size_t i = 0; i<parameter.size(); i++)
|
2013-12-24 20:33:55 +08:00
|
|
|
{
|
|
|
|
_Parameter.push_back(parameter[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ActionInterval* ActionFrame::getEasingAction(ActionInterval* action)
|
|
|
|
{
|
2013-12-26 16:29:59 +08:00
|
|
|
if (action == nullptr)
|
2013-12-24 20:33:55 +08:00
|
|
|
{
|
2013-12-26 16:29:59 +08:00
|
|
|
return nullptr;
|
2013-12-24 20:33:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (_easingType)
|
|
|
|
{
|
2013-12-27 10:43:49 +08:00
|
|
|
case FrameEaseType::Custom:
|
2013-12-24 20:33:55 +08:00
|
|
|
{
|
|
|
|
EaseBezierAction* cAction = EaseBezierAction::create(action);
|
|
|
|
cAction->setBezierParamer(_Parameter[0],_Parameter[1],_Parameter[2],_Parameter[3]);
|
|
|
|
return cAction;
|
|
|
|
}
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::LINERAR:
|
2013-12-24 20:33:55 +08:00
|
|
|
return action;
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::SINE_EASEIN:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseSineIn::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::SINE_EASEOUT:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseSineOut::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::SINE_EASEINOUT:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseSineInOut::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::QUAD_EASEIN:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseQuadraticActionIn::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::QUAD_EASEOUT:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseQuadraticActionOut::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::QUAD_EASEINOUT:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseQuadraticActionInOut::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::CUBIC_EASEIN:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseCubicActionIn::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::CUBIC_EASEOUT:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseCubicActionOut::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::CUBIC_EASEINOUT:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseCubicActionInOut::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::QUART_EASEIN:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseQuarticActionIn::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::QUART_EASEOUT:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseQuadraticActionOut::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::QUART_EASEINOUT:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseQuarticActionInOut::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::QUINT_EASEIN:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseQuinticActionIn::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::QUINT_EASEOUT:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseQuinticActionOut::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::QUINT_EASEINOUT:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseQuinticActionInOut::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::EXPO_EASEIN:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseExponentialIn::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::EXPO_EASEOUT:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseExponentialOut::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::EXPO_EASEINOUT:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseExponentialInOut::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::CIRC_EASEIN:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseCircleActionIn::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::CIRC_EASEOUT:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseCircleActionOut::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::CIRC_EASEINOUT:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseCircleActionInOut::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::ELASTIC_EASEIN:
|
2013-12-24 20:33:55 +08:00
|
|
|
{
|
2014-01-02 17:18:40 +08:00
|
|
|
return EaseElasticIn::create(action);
|
2013-12-24 20:33:55 +08:00
|
|
|
}
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::ELASTIC_EASEOUT:
|
2013-12-24 20:33:55 +08:00
|
|
|
{
|
2014-01-02 17:18:40 +08:00
|
|
|
return EaseElasticOut::create(action);
|
2013-12-24 20:33:55 +08:00
|
|
|
}
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::ELASTIC_EASEINOUT:
|
2013-12-24 20:33:55 +08:00
|
|
|
{
|
2014-01-02 17:18:40 +08:00
|
|
|
return EaseElasticInOut::create(action);
|
2013-12-24 20:33:55 +08:00
|
|
|
}
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::BACK_EASEIN:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseBackIn::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::BACK_EASEOUT:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseBackOut::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::BACK_EASEINOUT:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseBackInOut::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::BOUNCE_EASEIN:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseBounceIn::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::BOUNCE_EASEOUT:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseBounceOut::create(action);
|
|
|
|
break;
|
2013-12-27 17:21:13 +08:00
|
|
|
case FrameEaseType::BOUNCE_EASEINOUT:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseBounceInOut::create(action);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return action;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-09-20 22:23:13 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
ActionMoveFrame::ActionMoveFrame()
|
2013-12-26 16:29:59 +08:00
|
|
|
: _position(Point(0.0f,0.0f))
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
|
|
|
_frameType = (int)kKeyframeMove;
|
|
|
|
}
|
|
|
|
ActionMoveFrame::~ActionMoveFrame()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
void ActionMoveFrame::setPosition(Point pos)
|
|
|
|
{
|
|
|
|
_position = pos;
|
|
|
|
}
|
|
|
|
Point ActionMoveFrame::getPosition()
|
|
|
|
{
|
|
|
|
return _position;
|
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
ActionInterval* ActionMoveFrame::getAction(float fDuration)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2014-02-17 11:20:01 +08:00
|
|
|
return this->getEasingAction(MoveTo::create(fDuration,_position));
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
ActionScaleFrame::ActionScaleFrame()
|
2013-12-26 16:29:59 +08:00
|
|
|
: _scaleX(1.0f)
|
|
|
|
, _scaleY(1.0f)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
|
|
|
_frameType = (int)kKeyframeScale;
|
|
|
|
}
|
|
|
|
|
|
|
|
ActionScaleFrame::~ActionScaleFrame()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionScaleFrame::setScaleX(float scaleX)
|
|
|
|
{
|
|
|
|
_scaleX = scaleX;
|
|
|
|
}
|
|
|
|
|
|
|
|
float ActionScaleFrame::getScaleX()
|
|
|
|
{
|
|
|
|
return _scaleX;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionScaleFrame::setScaleY(float scaleY)
|
|
|
|
{
|
|
|
|
_scaleY = scaleY;
|
|
|
|
}
|
|
|
|
|
|
|
|
float ActionScaleFrame::getScaleY()
|
|
|
|
{
|
|
|
|
return _scaleY;
|
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
ActionInterval* ActionScaleFrame::getAction(float fDuration)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2014-02-17 11:20:01 +08:00
|
|
|
return this->getEasingAction(ScaleTo::create(fDuration,_scaleX,_scaleY));
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ActionRotationFrame::ActionRotationFrame()
|
2013-12-26 16:29:59 +08:00
|
|
|
: _rotation(0.0f)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
|
|
|
_frameType = (int)kKeyframeRotate;
|
|
|
|
}
|
|
|
|
|
|
|
|
ActionRotationFrame::~ActionRotationFrame()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionRotationFrame::setRotation(float rotation)
|
|
|
|
{
|
|
|
|
_rotation = rotation;
|
|
|
|
}
|
|
|
|
|
|
|
|
float ActionRotationFrame::getRotation()
|
|
|
|
{
|
|
|
|
return _rotation;
|
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
ActionInterval* ActionRotationFrame::getAction(float fDuration)
|
|
|
|
{
|
2014-02-17 11:20:01 +08:00
|
|
|
return this->getEasingAction(RotateTo::create(fDuration,_rotation));
|
2013-12-24 20:33:55 +08:00
|
|
|
}
|
|
|
|
ActionInterval* ActionRotationFrame::getAction(float fDuration,ActionFrame* srcFrame)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
ActionRotationFrame* srcRotationFrame = static_cast<ActionRotationFrame*>(srcFrame);
|
2013-12-26 16:29:59 +08:00
|
|
|
if (srcRotationFrame == nullptr)
|
2013-12-24 20:33:55 +08:00
|
|
|
{
|
|
|
|
return this->getAction(fDuration);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float diffRotation = _rotation - srcRotationFrame->_rotation;
|
2014-02-17 11:20:01 +08:00
|
|
|
return this->getEasingAction(RotateBy::create(fDuration,diffRotation));
|
2013-12-24 20:33:55 +08:00
|
|
|
}
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ActionFadeFrame::ActionFadeFrame()
|
2013-12-26 16:29:59 +08:00
|
|
|
: _opacity(255)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
|
|
|
_frameType = (int)kKeyframeFade;
|
|
|
|
}
|
|
|
|
|
|
|
|
ActionFadeFrame::~ActionFadeFrame()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionFadeFrame::setOpacity(int opacity)
|
|
|
|
{
|
|
|
|
_opacity = opacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ActionFadeFrame::getOpacity()
|
|
|
|
{
|
|
|
|
return _opacity;
|
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
ActionInterval* ActionFadeFrame::getAction(float fDuration)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2014-02-17 11:20:01 +08:00
|
|
|
return this->getEasingAction(FadeTo::create(fDuration,_opacity));
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ActionTintFrame::ActionTintFrame()
|
2013-12-26 16:29:59 +08:00
|
|
|
: _color(Color3B(255,255,255))
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
|
|
|
_frameType = (int)kKeyframeTint;
|
|
|
|
}
|
|
|
|
|
|
|
|
ActionTintFrame::~ActionTintFrame()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionTintFrame::setColor(Color3B ccolor)
|
|
|
|
{
|
|
|
|
_color = ccolor;
|
|
|
|
}
|
|
|
|
|
|
|
|
Color3B ActionTintFrame::getColor()
|
|
|
|
{
|
|
|
|
return _color;
|
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
ActionInterval* ActionTintFrame::getAction(float fDuration)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2014-02-17 11:20:01 +08:00
|
|
|
return this->getEasingAction(TintTo::create(fDuration,_color.r,_color.g,_color.b));
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
}
|