axmol/extensions/cocostudio/CCActionFrame.cpp

345 lines
8.9 KiB
C++
Raw Normal View History

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