2013-09-20 22:23:13 +08:00
|
|
|
/****************************************************************************
|
2013-12-26 16:29:59 +08:00
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
|
|
|
|
|
|
|
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"
|
2013-12-24 20:33:55 +08:00
|
|
|
#include "CCActionEaseEx.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-26 16:29:59 +08:00
|
|
|
, _easingType(FrameEaseType::FrameEase_Linear)
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionFrame::setEasingParameter(std::vector<float> parameter)
|
|
|
|
{
|
|
|
|
_Parameter.clear();
|
|
|
|
|
|
|
|
for ( unsigned int i = 0; i<parameter.size(); i++)
|
|
|
|
{
|
|
|
|
_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-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_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-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Linear:
|
2013-12-24 20:33:55 +08:00
|
|
|
return action;
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Sine_EaseIn:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseSineIn::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Sine_EaseOut:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseSineOut::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Sine_EaseInOut:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseSineInOut::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Quad_EaseIn:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseQuadraticActionIn::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Quad_EaseOut:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseQuadraticActionOut::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Quad_EaseInOut:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseQuadraticActionInOut::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Cubic_EaseIn:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseCubicActionIn::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Cubic_EaseOut:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseCubicActionOut::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Cubic_EaseInOut:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseCubicActionInOut::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Quart_EaseIn:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseQuarticActionIn::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Quart_EaseOut:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseQuadraticActionOut::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Quart_EaseInOut:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseQuarticActionInOut::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Quint_EaseIn:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseQuinticActionIn::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Quint_EaseOut:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseQuinticActionOut::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Quint_EaseInOut:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseQuinticActionInOut::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Expo_EaseIn:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseExponentialIn::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Expo_EaseOut:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseExponentialOut::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Expo_EaseInOut:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseExponentialInOut::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Circ_EaseIn:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseCircleActionIn::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Circ_EaseOut:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseCircleActionOut::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Circ_EaseInOut:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseCircleActionInOut::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Elastic_EaseIn:
|
2013-12-24 20:33:55 +08:00
|
|
|
{
|
|
|
|
EaseElasticIn* cAction = EaseElasticIn::create(action);
|
|
|
|
cAction->setPeriod(_Parameter[0]);
|
|
|
|
return cAction;
|
|
|
|
}
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Elastic_EaseOut:
|
2013-12-24 20:33:55 +08:00
|
|
|
{
|
|
|
|
EaseElasticOut* cAction = EaseElasticOut::create(action);
|
|
|
|
cAction->setPeriod(_Parameter[0]);
|
|
|
|
return cAction;
|
|
|
|
}
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Elastic_EaseInOut:
|
2013-12-24 20:33:55 +08:00
|
|
|
{
|
|
|
|
EaseElasticInOut* cAction = EaseElasticInOut::create(action);
|
|
|
|
cAction->setPeriod(_Parameter[0]);
|
|
|
|
return cAction;
|
|
|
|
}
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Back_EaseIn:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseBackIn::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Back_EaseOut:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseBackOut::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Back_EaseInOut:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseBackInOut::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Bounce_EaseIn:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseBounceIn::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_Bounce_EaseOut:
|
2013-12-24 20:33:55 +08:00
|
|
|
return EaseBounceOut::create(action);
|
|
|
|
break;
|
2013-12-26 16:29:59 +08:00
|
|
|
case FrameEaseType::FrameEase_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
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
return this->getEasingAction(CCMoveTo::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
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
return this->getEasingAction(CCScaleTo::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)
|
|
|
|
{
|
|
|
|
return this->getEasingAction(CCRotateTo::create(fDuration,_rotation));
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
return this->getEasingAction(CCRotateBy::create(fDuration,diffRotation));
|
|
|
|
}
|
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
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
return this->getEasingAction(CCFadeTo::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
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
return this->getEasingAction(CCTintTo::create(fDuration,_color.r,_color.g,_color.b));
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
}
|