axmol/extensions/cocostudio/ActionTimeline/CCFrame.cpp

807 lines
18 KiB
C++
Raw Normal View History

2014-06-11 11:10:07 +08:00
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
2022-02-24 18:51:36 +08:00
https://adxeproject.github.io/
2014-06-11 11:10:07 +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 "ActionTimeline/CCFrame.h"
#include "ActionTimeline/CCTimeLine.h"
#include "ActionTimeline/CCActionTimeline.h"
2014-08-29 15:39:52 +08:00
#include "2d/CCSpriteFrameCache.h"
#include "2d/CCSpriteFrame.h"
#include <exception>
#include <iostream>
2014-06-11 11:10:07 +08:00
USING_NS_CC;
NS_TIMELINE_BEGIN
2014-06-11 11:10:07 +08:00
// Frame
Frame::Frame()
: _frameIndex(0)
, _tween(true)
2014-10-17 20:43:01 +08:00
, _enterWhenPassed(false)
, _tweenType(tweenfunc::TweenType::Linear)
2014-06-11 11:10:07 +08:00
, _timeline(nullptr)
, _node(nullptr)
{
2015-04-09 18:10:37 +08:00
_easingParam.clear();
2014-06-11 11:10:07 +08:00
}
Frame::~Frame()
{
2015-04-09 18:10:37 +08:00
_easingParam.clear();
2014-06-11 11:10:07 +08:00
}
void Frame::emitEvent()
{
if (_timeline)
{
_timeline->getActionTimeline()->emitFrameEvent(this);
}
}
2014-06-11 11:10:07 +08:00
void Frame::cloneProperty(Frame* frame)
{
_frameIndex = frame->getFrameIndex();
2021-12-25 10:04:45 +08:00
_tween = frame->isTween();
2015-04-09 18:10:37 +08:00
_tweenType = frame->getTweenType();
setEasingParams(frame->getEasingParams());
}
void Frame::apply(float percent)
{
if (!_tween)
return;
2021-12-25 10:04:45 +08:00
2015-04-09 18:10:37 +08:00
float tweenpercent = percent;
2021-12-25 10:04:45 +08:00
if (_tweenType != tweenfunc::TWEEN_EASING_MAX && _tweenType != tweenfunc::Linear)
2015-04-09 18:10:37 +08:00
{
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());
2014-06-11 11:10:07 +08:00
}
2015-04-09 18:10:37 +08:00
const std::vector<float>& Frame::getEasingParams() const
{
return _easingParam;
}
2014-06-11 11:10:07 +08:00
// VisibleFrame
VisibleFrame* VisibleFrame::create()
{
2021-12-08 00:11:53 +08:00
VisibleFrame* frame = new VisibleFrame();
frame->autorelease();
return frame;
2014-06-11 11:10:07 +08:00
}
2021-12-25 10:04:45 +08:00
VisibleFrame::VisibleFrame() : _visible(true) {}
2014-06-11 11:10:07 +08:00
void VisibleFrame::onEnter(Frame* /*nextFrame*/, int /*currentFrameIndex*/)
2014-06-11 11:10:07 +08:00
{
if (_node)
{
_node->setVisible(_visible);
}
2014-06-11 11:10:07 +08:00
}
Frame* VisibleFrame::clone()
{
VisibleFrame* frame = VisibleFrame::create();
frame->setVisible(_visible);
frame->cloneProperty(this);
return frame;
}
// TextureFrame
TextureFrame* TextureFrame::create()
{
2021-12-08 00:11:53 +08:00
TextureFrame* frame = new TextureFrame();
frame->autorelease();
return frame;
2014-06-11 11:10:07 +08:00
}
2021-12-25 10:04:45 +08:00
TextureFrame::TextureFrame() : _sprite(nullptr), _textureName("") {}
2014-06-11 11:10:07 +08:00
void TextureFrame::setNode(Node* node)
2014-06-11 11:10:07 +08:00
{
Frame::setNode(node);
2014-06-12 19:56:15 +08:00
_sprite = dynamic_cast<Sprite*>(node);
2014-06-11 11:10:07 +08:00
}
void TextureFrame::onEnter(Frame* /*nextFrame*/, int /*currentFrameIndex*/)
2014-06-11 11:10:07 +08:00
{
2021-12-25 10:04:45 +08:00
if (_sprite)
2014-06-11 11:10:07 +08:00
{
2021-12-25 10:04:45 +08:00
auto spriteBlendFunc = _sprite->getBlendFunc();
2014-06-13 19:52:53 +08:00
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(_textureName);
2014-06-11 21:11:22 +08:00
2021-12-25 10:04:45 +08:00
if (spriteFrame != nullptr)
2014-06-11 21:11:22 +08:00
_sprite->setSpriteFrame(spriteFrame);
else
2014-06-13 19:52:53 +08:00
_sprite->setTexture(_textureName);
2021-12-25 10:04:45 +08:00
if (_sprite->getBlendFunc() != spriteBlendFunc)
2015-04-10 13:34:39 +08:00
_sprite->setBlendFunc(spriteBlendFunc);
2014-06-11 11:10:07 +08:00
}
}
Frame* TextureFrame::clone()
{
TextureFrame* frame = TextureFrame::create();
2014-06-13 19:52:53 +08:00
frame->setTextureName(_textureName);
2014-06-11 11:10:07 +08:00
frame->cloneProperty(this);
return frame;
}
// RotationFrame
RotationFrame* RotationFrame::create()
{
2021-12-08 00:11:53 +08:00
RotationFrame* frame = new RotationFrame();
frame->autorelease();
return frame;
2014-06-11 11:10:07 +08:00
}
2021-12-25 10:04:45 +08:00
RotationFrame::RotationFrame() : _rotation(0) {}
2014-06-11 11:10:07 +08:00
2021-12-25 10:04:45 +08:00
void RotationFrame::onEnter(Frame* nextFrame, int /*currentFrameIndex*/)
2014-06-11 11:10:07 +08:00
{
if (_node == nullptr)
{
return;
}
2021-12-25 10:04:45 +08:00
_node->setRotation(_rotation);
2014-10-23 17:37:18 +08:00
2021-12-25 10:04:45 +08:00
if (_tween)
2014-06-11 11:10:07 +08:00
{
_betwennRotation = static_cast<RotationFrame*>(nextFrame)->_rotation - _rotation;
}
}
2015-04-09 18:10:37 +08:00
void RotationFrame::onApply(float percent)
2014-06-11 11:10:07 +08:00
{
if (nullptr != _node && _betwennRotation != 0)
2014-06-11 11:10:07 +08:00
{
float rotation = _rotation + percent * _betwennRotation;
_node->setRotation(rotation);
}
}
Frame* RotationFrame::clone()
{
RotationFrame* frame = RotationFrame::create();
frame->setRotation(_rotation);
frame->cloneProperty(this);
return frame;
}
// SkewFrame
SkewFrame* SkewFrame::create()
{
2021-12-08 00:11:53 +08:00
SkewFrame* frame = new SkewFrame();
frame->autorelease();
return frame;
2014-06-11 11:10:07 +08:00
}
2021-12-25 10:04:45 +08:00
SkewFrame::SkewFrame() : _skewX(0), _skewY(0) {}
2014-06-11 11:10:07 +08:00
2021-12-25 10:04:45 +08:00
void SkewFrame::onEnter(Frame* nextFrame, int /*currentFrameIndex*/)
2014-06-11 11:10:07 +08:00
{
if (_node == nullptr)
{
2021-12-25 10:04:45 +08:00
return;
}
_node->setSkewX(_skewX);
_node->setSkewY(_skewY);
2014-10-23 17:37:18 +08:00
2021-12-25 10:04:45 +08:00
if (_tween)
2014-06-11 11:10:07 +08:00
{
_betweenSkewX = static_cast<SkewFrame*>(nextFrame)->_skewX - _skewX;
_betweenSkewY = static_cast<SkewFrame*>(nextFrame)->_skewY - _skewY;
}
}
2015-04-09 18:10:37 +08:00
void SkewFrame::onApply(float percent)
2014-06-11 11:10:07 +08:00
{
if ((nullptr != _node) && (_betweenSkewX != 0 || _betweenSkewY != 0))
2014-06-11 11:10:07 +08:00
{
float skewx = _skewX + percent * _betweenSkewX;
float skewy = _skewY + percent * _betweenSkewY;
2021-12-25 10:04:45 +08:00
2014-06-11 11:10:07 +08:00
_node->setSkewX(skewx);
_node->setSkewY(skewy);
}
}
Frame* SkewFrame::clone()
{
SkewFrame* frame = SkewFrame::create();
frame->setSkewX(_skewX);
frame->setSkewY(_skewY);
frame->cloneProperty(this);
return frame;
}
// RotationSkewFrame
RotationSkewFrame* RotationSkewFrame::create()
{
2021-12-08 00:11:53 +08:00
RotationSkewFrame* frame = new RotationSkewFrame();
frame->autorelease();
return frame;
2014-06-11 11:10:07 +08:00
}
2021-12-25 10:04:45 +08:00
RotationSkewFrame::RotationSkewFrame() {}
2014-06-11 11:10:07 +08:00
2021-12-25 10:04:45 +08:00
void RotationSkewFrame::onEnter(Frame* nextFrame, int /*currentFrameIndex*/)
2014-06-11 11:10:07 +08:00
{
if (_node == nullptr)
{
2021-12-25 10:04:45 +08:00
return;
}
_node->setRotationSkewX(_skewX);
_node->setRotationSkewY(_skewY);
2014-10-23 17:37:18 +08:00
2014-06-11 11:10:07 +08:00
if (_tween)
{
_betweenSkewX = static_cast<RotationSkewFrame*>(nextFrame)->_skewX - _skewX;
_betweenSkewY = static_cast<RotationSkewFrame*>(nextFrame)->_skewY - _skewY;
}
}
2015-04-09 18:10:37 +08:00
void RotationSkewFrame::onApply(float percent)
2014-06-11 11:10:07 +08:00
{
if ((nullptr != _node) && (_betweenSkewX != 0 || _betweenSkewY != 0))
2014-06-11 11:10:07 +08:00
{
float skewx = _skewX + percent * _betweenSkewX;
float skewy = _skewY + percent * _betweenSkewY;
2021-12-25 10:04:45 +08:00
2014-06-11 11:10:07 +08:00
_node->setRotationSkewX(skewx);
_node->setRotationSkewY(skewy);
}
}
Frame* RotationSkewFrame::clone()
{
RotationSkewFrame* frame = RotationSkewFrame::create();
frame->setSkewX(_skewX);
frame->setSkewY(_skewY);
frame->cloneProperty(this);
return frame;
}
// PositionFrame
PositionFrame* PositionFrame::create()
{
2021-12-08 00:11:53 +08:00
PositionFrame* frame = new PositionFrame();
frame->autorelease();
return frame;
2014-06-11 11:10:07 +08:00
}
2021-12-25 10:04:45 +08:00
PositionFrame::PositionFrame() : _position(0, 0) {}
2014-06-11 11:10:07 +08:00
2021-12-25 10:04:45 +08:00
void PositionFrame::onEnter(Frame* nextFrame, int /*currentFrameIndex*/)
2014-06-11 11:10:07 +08:00
{
if (_node == nullptr)
{
2021-12-25 10:04:45 +08:00
return;
}
_node->setPosition(_position);
2021-12-25 10:04:45 +08:00
if (_tween)
2014-06-11 11:10:07 +08:00
{
_betweenX = static_cast<PositionFrame*>(nextFrame)->_position.x - _position.x;
_betweenY = static_cast<PositionFrame*>(nextFrame)->_position.y - _position.y;
}
}
2015-04-09 18:10:37 +08:00
void PositionFrame::onApply(float percent)
2014-06-11 11:10:07 +08:00
{
if ((nullptr != _node) && (_betweenX != 0 || _betweenY != 0))
2014-06-11 11:10:07 +08:00
{
Point p;
p.x = _position.x + _betweenX * percent;
p.y = _position.y + _betweenY * percent;
2021-12-25 10:04:45 +08:00
2014-06-11 11:10:07 +08:00
_node->setPosition(p);
}
}
Frame* PositionFrame::clone()
{
PositionFrame* frame = PositionFrame::create();
frame->setPosition(_position);
frame->cloneProperty(this);
return frame;
}
// ScaleFrame
ScaleFrame* ScaleFrame::create()
{
2021-12-08 00:11:53 +08:00
ScaleFrame* frame = new ScaleFrame();
frame->autorelease();
return frame;
2014-06-11 11:10:07 +08:00
}
2021-12-25 10:04:45 +08:00
ScaleFrame::ScaleFrame() : _scaleX(1), _scaleY(1) {}
2014-06-11 11:10:07 +08:00
2021-12-25 10:04:45 +08:00
void ScaleFrame::onEnter(Frame* nextFrame, int /*currentFrameIndex*/)
2014-06-11 11:10:07 +08:00
{
if (_node == nullptr)
{
2021-12-25 10:04:45 +08:00
return;
}
2021-12-25 10:04:45 +08:00
_node->setScaleX(_scaleX);
_node->setScaleY(_scaleY);
2014-10-23 17:37:18 +08:00
2021-12-25 10:04:45 +08:00
if (_tween)
2014-06-11 11:10:07 +08:00
{
_betweenScaleX = static_cast<ScaleFrame*>(nextFrame)->_scaleX - _scaleX;
_betweenScaleY = static_cast<ScaleFrame*>(nextFrame)->_scaleY - _scaleY;
}
}
2015-04-09 18:10:37 +08:00
void ScaleFrame::onApply(float percent)
2014-06-11 11:10:07 +08:00
{
if ((nullptr != _node) && (_betweenScaleX != 0 || _betweenScaleY != 0))
2014-06-11 11:10:07 +08:00
{
float scaleX = _scaleX + _betweenScaleX * percent;
float scaleY = _scaleY + _betweenScaleY * percent;
2021-12-25 10:04:45 +08:00
2014-06-11 11:10:07 +08:00
_node->setScaleX(scaleX);
_node->setScaleY(scaleY);
}
}
Frame* ScaleFrame::clone()
{
ScaleFrame* frame = ScaleFrame::create();
frame->setScaleX(_scaleX);
2021-12-25 10:04:45 +08:00
frame->setScaleY(_scaleY);
2014-06-11 11:10:07 +08:00
frame->cloneProperty(this);
return frame;
}
// AnchorPointFrame
AnchorPointFrame* AnchorPointFrame::create()
{
2021-12-08 00:11:53 +08:00
AnchorPointFrame* frame = new AnchorPointFrame();
frame->autorelease();
return frame;
2014-06-11 11:10:07 +08:00
}
2021-12-25 10:04:45 +08:00
AnchorPointFrame::AnchorPointFrame() : _anchorPoint(0.5f, 0.5f) {}
2014-06-11 11:10:07 +08:00
2021-12-25 10:04:45 +08:00
void AnchorPointFrame::onEnter(Frame* nextFrame, int /*currentFrameIndex*/)
2014-06-11 11:10:07 +08:00
{
if (_node == nullptr)
{
2021-12-25 10:04:45 +08:00
return;
}
if (_tween)
{
_betweenAnchorPoint = static_cast<AnchorPointFrame*>(nextFrame)->_anchorPoint - _anchorPoint;
}
2014-06-11 11:10:07 +08:00
_node->setAnchorPoint(_anchorPoint);
}
Frame* AnchorPointFrame::clone()
{
AnchorPointFrame* frame = AnchorPointFrame::create();
frame->setAnchorPoint(_anchorPoint);
frame->cloneProperty(this);
return frame;
}
void AnchorPointFrame::onApply(float percent)
{
if ((nullptr != _node) && (_betweenAnchorPoint.x != 0 || _betweenAnchorPoint.y != 0))
{
auto applyAnchorP = _betweenAnchorPoint * percent + _anchorPoint;
_node->setAnchorPoint(applyAnchorP);
}
}
2014-06-11 11:10:07 +08:00
// InnerActionFrame
2015-01-12 13:54:17 +08:00
const std::string InnerActionFrame::AnimationAllName = "-- ALL --";
2014-06-11 11:10:07 +08:00
InnerActionFrame* InnerActionFrame::create()
{
2021-12-08 00:11:53 +08:00
InnerActionFrame* frame = new InnerActionFrame();
frame->autorelease();
return frame;
2014-06-11 11:10:07 +08:00
}
InnerActionFrame::InnerActionFrame()
2021-12-25 10:04:45 +08:00
: _innerActionType(InnerActionType::SingleFrame)
, _startFrameIndex(0)
, _endFrameIndex(0)
, _singleFrameIndex(0)
, _animationName("")
, _enterWithName(false)
{}
2014-06-11 11:10:07 +08:00
void InnerActionFrame::onEnter(Frame* /*nextFrame*/, int /*currentFrameIndex*/)
2014-06-11 11:10:07 +08:00
{
if (_node == nullptr)
{
2021-12-25 10:04:45 +08:00
return;
}
2015-01-14 13:02:30 +08:00
auto innerActiontimeline = static_cast<ActionTimeline*>(_node->getActionByTag(_node->getTag()));
2021-12-25 10:04:45 +08:00
if (nullptr == innerActiontimeline)
return;
2021-12-25 10:04:45 +08:00
if (InnerActionType::SingleFrame == _innerActionType)
{
2015-01-14 13:02:30 +08:00
innerActiontimeline->gotoFrameAndPause(_singleFrameIndex);
return;
}
2021-12-25 10:04:45 +08:00
2015-01-14 13:02:30 +08:00
int innerStart = _startFrameIndex;
2021-12-25 10:04:45 +08:00
int innerEnd = _endFrameIndex;
if (_enterWithName)
{
2015-01-12 13:54:17 +08:00
if (_animationName == AnimationAllName)
{
2015-01-14 13:02:30 +08:00
innerStart = 0;
2021-12-25 10:04:45 +08:00
innerEnd = innerActiontimeline->getDuration();
}
2021-12-25 10:04:45 +08:00
else if (innerActiontimeline->IsAnimationInfoExists(_animationName))
{
2015-01-14 13:02:30 +08:00
AnimationInfo info = innerActiontimeline->getAnimationInfo(_animationName);
2021-12-25 10:04:45 +08:00
innerStart = info.startIndex;
innerEnd = info.endIndex;
}
else
{
CCLOG("Animation %s not exists!", _animationName.c_str());
}
}
2021-12-25 10:04:45 +08:00
int duration = _timeline->getActionTimeline()->getDuration();
2021-12-25 10:04:45 +08:00
int odddiff = duration - _frameIndex - innerEnd + innerStart;
if (odddiff < 0)
{
2021-12-25 10:04:45 +08:00
innerEnd += odddiff;
}
2021-12-25 10:04:45 +08:00
if (InnerActionType::NoLoopAction == _innerActionType)
{
2015-01-14 13:02:30 +08:00
innerActiontimeline->gotoFrameAndPlay(innerStart, innerEnd, false);
}
else if (InnerActionType::LoopAction == _innerActionType)
{
2015-01-14 13:02:30 +08:00
innerActiontimeline->gotoFrameAndPlay(innerStart, innerEnd, true);
}
}
void InnerActionFrame::setStartFrameIndex(int frameIndex)
{
if (_enterWithName)
{
CCLOG(" cannot set start when enter frame with name. setEnterWithName false firstly!");
2015-11-26 16:49:01 +08:00
return;
}
2015-11-26 16:49:01 +08:00
_startFrameIndex = frameIndex;
2014-06-11 11:10:07 +08:00
}
void InnerActionFrame::setEndFrameIndex(int frameIndex)
{
if (_enterWithName)
{
CCLOG(" cannot set end when enter frame with name. setEnterWithName false firstly!");
2015-11-26 16:49:01 +08:00
return;
}
2015-11-26 16:49:01 +08:00
_endFrameIndex = frameIndex;
}
2021-12-26 23:26:34 +08:00
void InnerActionFrame::setAnimationName(std::string_view animationName)
{
if (!_enterWithName)
{
CCLOG(" cannot set aniamtioname when enter frame with index. setEnterWithName true firstly!");
2015-11-26 16:49:01 +08:00
return;
}
2015-11-26 16:49:01 +08:00
_animationName = animationName;
}
2014-06-11 11:10:07 +08:00
Frame* InnerActionFrame::clone()
{
InnerActionFrame* frame = InnerActionFrame::create();
frame->setInnerActionType(_innerActionType);
frame->setSingleFrameIndex(_singleFrameIndex);
2021-12-25 10:04:45 +08:00
if (_enterWithName)
2015-01-12 11:09:19 +08:00
{
frame->setEnterWithName(true);
frame->setAnimationName(_animationName);
}
else
{
frame->setStartFrameIndex(_startFrameIndex);
frame->setEndFrameIndex(_endFrameIndex);
}
2014-06-11 11:10:07 +08:00
frame->cloneProperty(this);
return frame;
}
// ColorFrame
ColorFrame* ColorFrame::create()
{
2021-12-08 00:11:53 +08:00
ColorFrame* frame = new ColorFrame();
frame->autorelease();
return frame;
2014-06-11 11:10:07 +08:00
}
2021-12-25 10:04:45 +08:00
ColorFrame::ColorFrame() : _color(Color3B(255, 255, 255)) {}
2014-06-11 11:10:07 +08:00
2021-12-25 10:04:45 +08:00
void ColorFrame::onEnter(Frame* nextFrame, int /*currentFrameIndex*/)
2014-06-11 11:10:07 +08:00
{
if (_node == nullptr)
{
2021-12-25 10:04:45 +08:00
return;
}
_node->setColor(_color);
2014-10-23 17:37:18 +08:00
2021-12-25 10:04:45 +08:00
if (_tween)
2014-06-11 11:10:07 +08:00
{
const Color3B& color = static_cast<ColorFrame*>(nextFrame)->_color;
2021-12-25 10:04:45 +08:00
_betweenRed = color.r - _color.r;
_betweenGreen = color.g - _color.g;
_betweenBlue = color.b - _color.b;
2014-06-11 11:10:07 +08:00
}
}
2015-04-09 18:10:37 +08:00
void ColorFrame::onApply(float percent)
2014-06-11 11:10:07 +08:00
{
if ((nullptr != _node) && (_betweenRed != 0 || _betweenGreen != 0 || _betweenBlue != 0))
2014-06-11 11:10:07 +08:00
{
Color3B color;
2021-12-25 10:04:45 +08:00
color.r = _color.r + _betweenRed * percent;
color.g = _color.g + _betweenGreen * percent;
color.b = _color.b + _betweenBlue * percent;
2014-06-11 11:10:07 +08:00
_node->setColor(color);
}
}
Frame* ColorFrame::clone()
{
ColorFrame* frame = ColorFrame::create();
frame->setColor(_color);
frame->cloneProperty(this);
return frame;
}
// AlphaFrame
AlphaFrame* AlphaFrame::create()
{
2021-12-08 00:11:53 +08:00
AlphaFrame* frame = new AlphaFrame();
frame->autorelease();
return frame;
}
2021-12-25 10:04:45 +08:00
AlphaFrame::AlphaFrame() : _alpha(255) {}
2021-12-25 10:04:45 +08:00
void AlphaFrame::onEnter(Frame* nextFrame, int /*currentFrameIndex*/)
{
if (_node == nullptr)
{
2021-12-25 10:04:45 +08:00
return;
}
_node->setOpacity(_alpha);
if (_tween)
{
_betweenAlpha = static_cast<AlphaFrame*>(nextFrame)->_alpha - _alpha;
}
}
2015-04-09 18:10:37 +08:00
void AlphaFrame::onApply(float percent)
{
if (nullptr != _node)
{
2019-11-25 01:35:26 +08:00
uint8_t alpha = _alpha + _betweenAlpha * percent;
_node->setOpacity(alpha);
}
}
Frame* AlphaFrame::clone()
{
AlphaFrame* frame = AlphaFrame::create();
frame->setAlpha(_alpha);
frame->cloneProperty(this);
return frame;
}
2014-06-11 11:10:07 +08:00
// EventFrame
EventFrame* EventFrame::create()
{
2021-12-08 00:11:53 +08:00
EventFrame* frame = new EventFrame();
frame->init();
frame->autorelease();
return frame;
2014-06-11 11:10:07 +08:00
}
2014-10-17 20:43:01 +08:00
void EventFrame::init()
{
_enterWhenPassed = true;
}
2021-12-25 10:04:45 +08:00
EventFrame::EventFrame() : _event(""), _action(nullptr) {}
2014-06-11 11:10:07 +08:00
2014-12-12 18:02:03 +08:00
void EventFrame::setNode(cocos2d::Node* node)
{
Frame::setNode(node);
_action = _timeline->getActionTimeline();
}
void EventFrame::onEnter(Frame* /*nextFrame*/, int currentFrameIndex)
2014-06-11 11:10:07 +08:00
{
2021-12-25 10:04:45 +08:00
if (static_cast<int>(_frameIndex) < _action->getStartFrame() ||
static_cast<int>(_frameIndex) > _action->getEndFrame())
2014-12-12 18:02:03 +08:00
return;
if (currentFrameIndex >= static_cast<int>(_frameIndex))
2014-10-23 17:37:18 +08:00
emitEvent();
2014-06-11 11:10:07 +08:00
}
Frame* EventFrame::clone()
{
EventFrame* frame = EventFrame::create();
frame->setEvent(_event);
frame->cloneProperty(this);
return frame;
}
// ZOrderFrame
ZOrderFrame* ZOrderFrame::create()
{
2021-12-08 00:11:53 +08:00
ZOrderFrame* frame = new ZOrderFrame();
frame->autorelease();
return frame;
2014-06-11 11:10:07 +08:00
}
2021-12-25 10:04:45 +08:00
ZOrderFrame::ZOrderFrame() : _zorder(0) {}
2014-06-11 11:10:07 +08:00
void ZOrderFrame::onEnter(Frame* /*nextFrame*/, int /*currentFrameIndex*/)
2014-06-11 11:10:07 +08:00
{
2021-12-25 10:04:45 +08:00
if (_node)
_node->setLocalZOrder(_zorder);
2014-06-11 11:10:07 +08:00
}
Frame* ZOrderFrame::clone()
{
ZOrderFrame* frame = ZOrderFrame::create();
frame->setZOrder(_zorder);
frame->cloneProperty(this);
return frame;
}
2015-04-10 13:34:39 +08:00
// BlendFuncFrame
BlendFuncFrame* BlendFuncFrame::create()
{
2021-12-08 00:11:53 +08:00
BlendFuncFrame* frame = new BlendFuncFrame();
frame->autorelease();
return frame;
2015-04-10 13:34:39 +08:00
}
2021-12-25 10:04:45 +08:00
BlendFuncFrame::BlendFuncFrame() : _blendFunc(BlendFunc::ALPHA_PREMULTIPLIED) {}
2015-04-10 13:34:39 +08:00
void BlendFuncFrame::onEnter(Frame* /*nextFrame*/, int /*currentFrameIndex*/)
2015-04-10 13:34:39 +08:00
{
2021-12-25 10:04:45 +08:00
if (_node)
2015-04-10 13:34:39 +08:00
{
auto blendnode = dynamic_cast<BlendProtocol*>(_node);
2021-12-25 10:04:45 +08:00
if (blendnode)
2015-04-10 13:34:39 +08:00
blendnode->setBlendFunc(_blendFunc);
}
}
Frame* BlendFuncFrame::clone()
{
BlendFuncFrame* frame = BlendFuncFrame::create();
frame->setBlendFunc(_blendFunc);
frame->cloneProperty(this);
2021-12-25 10:04:45 +08:00
2015-04-10 13:34:39 +08:00
return frame;
}
2021-12-25 10:04:45 +08:00
// PlayableFrame
const std::string PlayableFrame::START_ACT = "start";
const std::string PlayableFrame::STOP_ACT = "stop";
2016-01-12 17:21:01 +08:00
const std::string PlayableFrame::PLAYABLE_EXTENTION = "playable_extension";
PlayableFrame* PlayableFrame::create()
{
2021-12-08 00:11:53 +08:00
auto frame = new PlayableFrame();
frame->autorelease();
return frame;
2016-01-12 17:21:01 +08:00
}
2015-04-10 13:34:39 +08:00
2021-12-25 10:04:45 +08:00
PlayableFrame::PlayableFrame() : _playableAct("") {}
2016-01-12 17:21:01 +08:00
void PlayableFrame::onEnter(Frame* /*nextFrame*/, int /*currentFrameINdex*/)
2016-01-12 17:21:01 +08:00
{
auto playableNode = dynamic_cast<PlayableProtocol*>(_node);
2021-12-25 10:04:45 +08:00
if (nullptr == playableNode) // may be a playable component
2016-01-12 17:21:01 +08:00
playableNode = dynamic_cast<PlayableProtocol*>(_node->getComponent(PLAYABLE_EXTENTION));
if (nullptr == playableNode)
return;
2021-12-25 10:04:45 +08:00
if (_playableAct == START_ACT)
2016-01-12 17:21:01 +08:00
playableNode->start();
2021-12-25 10:04:45 +08:00
else if (_playableAct == STOP_ACT)
2016-01-12 17:21:01 +08:00
playableNode->stop();
}
Frame* PlayableFrame::clone()
{
PlayableFrame* frame = PlayableFrame::create();
frame->cloneProperty(this);
frame->setPlayableAct(_playableAct);
return frame;
}
NS_TIMELINE_END