mirror of https://github.com/axmolengine/axmol.git
Merge pull request #8975 from 2youyouo2/v3_EventFrame
update event frame
This commit is contained in:
commit
d0edba2db3
|
@ -78,6 +78,7 @@ ActionTimeline::ActionTimeline()
|
|||
, _startFrame(0)
|
||||
, _endFrame(0)
|
||||
, _frameEventListener(nullptr)
|
||||
, _lastFrameListener(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -186,6 +187,9 @@ void ActionTimeline::step(float delta)
|
|||
|
||||
if(_time > _endFrame * _frameInternal)
|
||||
{
|
||||
if(_lastFrameListener != nullptr)
|
||||
_lastFrameListener();
|
||||
|
||||
_playing = _loop;
|
||||
if(!_playing)
|
||||
_time = _endFrame * _frameInternal;
|
||||
|
@ -272,6 +276,15 @@ void ActionTimeline::clearFrameEventCallFunc()
|
|||
_frameEventListener = nullptr;
|
||||
}
|
||||
|
||||
void ActionTimeline::setLastFrameCallFunc(std::function<void()> listener)
|
||||
{
|
||||
_lastFrameListener = listener;
|
||||
}
|
||||
|
||||
void ActionTimeline::clearLastFrameCallFunc()
|
||||
{
|
||||
_lastFrameListener = nullptr;
|
||||
}
|
||||
|
||||
void ActionTimeline::emitFrameEvent(Frame* frame)
|
||||
{
|
||||
|
@ -283,6 +296,9 @@ void ActionTimeline::emitFrameEvent(Frame* frame)
|
|||
|
||||
void ActionTimeline::gotoFrame(int frameIndex)
|
||||
{
|
||||
if(_target == nullptr)
|
||||
return;
|
||||
|
||||
ssize_t size = _timelineList.size();
|
||||
for(ssize_t i = 0; i < size; i++)
|
||||
{
|
||||
|
|
|
@ -129,6 +129,10 @@ public:
|
|||
void setFrameEventCallFunc(std::function<void(Frame *)> listener);
|
||||
void clearFrameEventCallFunc();
|
||||
|
||||
/** Last frame callback will call when arriving last frame */
|
||||
void setLastFrameCallFunc(std::function<void()> listener);
|
||||
void clearLastFrameCallFunc();
|
||||
|
||||
/** Inherit from Action. */
|
||||
|
||||
/** Returns a clone of ActionTimeline */
|
||||
|
@ -163,6 +167,7 @@ protected:
|
|||
bool _loop;
|
||||
|
||||
std::function<void(Frame*)> _frameEventListener;
|
||||
std::function<void()> _lastFrameListener;
|
||||
};
|
||||
|
||||
NS_TIMELINE_END
|
||||
|
|
|
@ -79,7 +79,7 @@ VisibleFrame::VisibleFrame()
|
|||
{
|
||||
}
|
||||
|
||||
void VisibleFrame::onEnter(Frame *nextFrame)
|
||||
void VisibleFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
|
||||
{
|
||||
_node->setVisible(_visible);
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ void TextureFrame::setNode(Node* node)
|
|||
_sprite = dynamic_cast<Sprite*>(node);
|
||||
}
|
||||
|
||||
void TextureFrame::onEnter(Frame *nextFrame)
|
||||
void TextureFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
|
||||
{
|
||||
if(_sprite)
|
||||
{
|
||||
|
@ -166,10 +166,10 @@ RotationFrame::RotationFrame()
|
|||
{
|
||||
}
|
||||
|
||||
void RotationFrame::onEnter(Frame *nextFrame)
|
||||
void RotationFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
|
||||
{
|
||||
_node->setRotation(_rotation);
|
||||
|
||||
|
||||
if(_tween)
|
||||
{
|
||||
_betwennRotation = static_cast<RotationFrame*>(nextFrame)->_rotation - _rotation;
|
||||
|
@ -216,11 +216,11 @@ SkewFrame::SkewFrame()
|
|||
{
|
||||
}
|
||||
|
||||
void SkewFrame::onEnter(Frame *nextFrame)
|
||||
void SkewFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
|
||||
{
|
||||
_node->setSkewX(_skewX);
|
||||
_node->setSkewY(_skewY);
|
||||
|
||||
|
||||
if(_tween)
|
||||
{
|
||||
_betweenSkewX = static_cast<SkewFrame*>(nextFrame)->_skewX - _skewX;
|
||||
|
@ -271,11 +271,11 @@ RotationSkewFrame::RotationSkewFrame()
|
|||
{
|
||||
}
|
||||
|
||||
void RotationSkewFrame::onEnter(Frame *nextFrame)
|
||||
void RotationSkewFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
|
||||
{
|
||||
_node->setRotationSkewX(_skewX);
|
||||
_node->setRotationSkewY(_skewY);
|
||||
|
||||
|
||||
if (_tween)
|
||||
{
|
||||
_betweenSkewX = static_cast<RotationSkewFrame*>(nextFrame)->_skewX - _skewX;
|
||||
|
@ -325,7 +325,7 @@ PositionFrame::PositionFrame()
|
|||
{
|
||||
}
|
||||
|
||||
void PositionFrame::onEnter(Frame *nextFrame)
|
||||
void PositionFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
|
||||
{
|
||||
_node->setPosition(_position);
|
||||
|
||||
|
@ -378,11 +378,11 @@ ScaleFrame::ScaleFrame()
|
|||
{
|
||||
}
|
||||
|
||||
void ScaleFrame::onEnter(Frame *nextFrame)
|
||||
void ScaleFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
|
||||
{
|
||||
_node->setScaleX(_scaleX);
|
||||
_node->setScaleY(_scaleY);
|
||||
|
||||
|
||||
if(_tween)
|
||||
{
|
||||
_betweenScaleX = static_cast<ScaleFrame*>(nextFrame)->_scaleX - _scaleX;
|
||||
|
@ -432,7 +432,7 @@ AnchorPointFrame::AnchorPointFrame()
|
|||
{
|
||||
}
|
||||
|
||||
void AnchorPointFrame::onEnter(Frame *nextFrame)
|
||||
void AnchorPointFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
|
||||
{
|
||||
_node->setAnchorPoint(_anchorPoint);
|
||||
}
|
||||
|
@ -469,7 +469,7 @@ InnerActionFrame::InnerActionFrame()
|
|||
{
|
||||
}
|
||||
|
||||
void InnerActionFrame::onEnter(Frame *nextFrame)
|
||||
void InnerActionFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -505,11 +505,11 @@ ColorFrame::ColorFrame()
|
|||
{
|
||||
}
|
||||
|
||||
void ColorFrame::onEnter(Frame *nextFrame)
|
||||
void ColorFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
|
||||
{
|
||||
_node->setOpacity(_alpha);
|
||||
_node->setColor(_color);
|
||||
|
||||
|
||||
if(_tween)
|
||||
{
|
||||
_betweenAlpha = static_cast<ColorFrame*>(nextFrame)->_alpha - _alpha;
|
||||
|
@ -573,9 +573,10 @@ EventFrame::EventFrame()
|
|||
{
|
||||
}
|
||||
|
||||
void EventFrame::onEnter(Frame *nextFrame)
|
||||
void EventFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
|
||||
{
|
||||
emitEvent();
|
||||
if(currentFrameIndex>=_frameIndex)
|
||||
emitEvent();
|
||||
}
|
||||
|
||||
|
||||
|
@ -608,7 +609,7 @@ ZOrderFrame::ZOrderFrame()
|
|||
{
|
||||
}
|
||||
|
||||
void ZOrderFrame::onEnter(Frame *nextFrame)
|
||||
void ZOrderFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
|
||||
{
|
||||
if(_node)
|
||||
_node->setLocalZOrder(_zorder);
|
||||
|
|
|
@ -56,7 +56,7 @@ public:
|
|||
|
||||
virtual bool isEnterWhenPassed() { return _enterWhenPassed; }
|
||||
|
||||
virtual void onEnter(Frame *nextFrame) = 0;
|
||||
virtual void onEnter(Frame* nextFrame, int currentFrameIndex) = 0;
|
||||
virtual void apply(float percent) {}
|
||||
|
||||
virtual Frame* clone() = 0;
|
||||
|
@ -84,7 +84,7 @@ public:
|
|||
|
||||
VisibleFrame();
|
||||
|
||||
virtual void onEnter(Frame *nextFrame) override;
|
||||
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
|
||||
virtual Frame* clone() override;
|
||||
|
||||
inline void setVisible(bool visible) { _visible = visible;}
|
||||
|
@ -104,7 +104,7 @@ public:
|
|||
|
||||
virtual void setNode(cocos2d::Node* node);
|
||||
|
||||
virtual void onEnter(Frame *nextFrame) override;
|
||||
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
|
||||
virtual Frame* clone() override;
|
||||
|
||||
inline void setTextureName(std::string textureName) { _textureName = textureName;}
|
||||
|
@ -122,7 +122,7 @@ public:
|
|||
|
||||
RotationFrame();
|
||||
|
||||
virtual void onEnter(Frame *nextFrame) override;
|
||||
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
|
||||
virtual void apply(float percent) override;
|
||||
virtual Frame* clone() override;
|
||||
|
||||
|
@ -141,7 +141,7 @@ public:
|
|||
|
||||
SkewFrame();
|
||||
|
||||
virtual void onEnter(Frame *nextFrame) override;
|
||||
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
|
||||
virtual void apply(float percent) override;
|
||||
virtual Frame* clone() override;
|
||||
|
||||
|
@ -166,7 +166,7 @@ public:
|
|||
|
||||
RotationSkewFrame();
|
||||
|
||||
virtual void onEnter(Frame *nextFrame) override;
|
||||
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
|
||||
virtual void apply(float percent) override;
|
||||
virtual Frame* clone() override;
|
||||
};
|
||||
|
@ -179,7 +179,7 @@ public:
|
|||
|
||||
PositionFrame();
|
||||
|
||||
virtual void onEnter(Frame *nextFrame) override;
|
||||
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
|
||||
virtual void apply(float percent) override;
|
||||
virtual Frame* clone() override;
|
||||
|
||||
|
@ -205,7 +205,7 @@ public:
|
|||
|
||||
ScaleFrame();
|
||||
|
||||
virtual void onEnter(Frame *nextFrame) override;
|
||||
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
|
||||
virtual void apply(float percent) override;
|
||||
virtual Frame* clone() override;
|
||||
|
||||
|
@ -232,7 +232,7 @@ public:
|
|||
|
||||
AnchorPointFrame();
|
||||
|
||||
virtual void onEnter(Frame *nextFrame) override;
|
||||
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
|
||||
virtual Frame* clone() override;
|
||||
|
||||
inline void setAnchorPoint(const cocos2d::Point& point) { _anchorPoint = point; }
|
||||
|
@ -257,7 +257,7 @@ public:
|
|||
static InnerActionFrame* create();
|
||||
InnerActionFrame();
|
||||
|
||||
virtual void onEnter(Frame *nextFrame) override;
|
||||
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
|
||||
virtual Frame* clone() override;
|
||||
|
||||
inline void setInnerActionType(InnerActionType type) { _innerActionType = type; }
|
||||
|
@ -278,7 +278,7 @@ public:
|
|||
static ColorFrame* create();
|
||||
ColorFrame();
|
||||
|
||||
virtual void onEnter(Frame *nextFrame) override;
|
||||
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
|
||||
virtual void apply(float percent) override;
|
||||
virtual Frame* clone() override;
|
||||
|
||||
|
@ -307,7 +307,7 @@ public:
|
|||
|
||||
EventFrame();
|
||||
|
||||
virtual void onEnter(Frame *nextFrame) override;
|
||||
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
|
||||
virtual Frame* clone() override;
|
||||
|
||||
inline void setEvent(std::string event) { _event = event;}
|
||||
|
@ -324,7 +324,7 @@ public:
|
|||
|
||||
ZOrderFrame();
|
||||
|
||||
virtual void onEnter(Frame *nextFrame) override;
|
||||
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
|
||||
virtual Frame* clone() override;
|
||||
|
||||
inline void setZOrder(int zorder) { _zorder = zorder;}
|
||||
|
|
|
@ -202,7 +202,7 @@ void Timeline::binarySearchKeyFrame(int frameIndex)
|
|||
if(needEnterFrame || _currentKeyFrame != from)
|
||||
{
|
||||
_currentKeyFrame = from;
|
||||
_currentKeyFrame->onEnter(to);
|
||||
_currentKeyFrame->onEnter(to, frameIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -252,7 +252,7 @@ void Timeline::updateCurrentKeyFrame(int frameIndex)
|
|||
if(frameIndex > from->getFrameIndex() && frameIndex < to->getFrameIndex())
|
||||
break;
|
||||
if(from->isEnterWhenPassed())
|
||||
from->onEnter(to);
|
||||
from->onEnter(to, from->getFrameIndex());
|
||||
}
|
||||
while (true);
|
||||
|
||||
|
@ -264,7 +264,7 @@ void Timeline::updateCurrentKeyFrame(int frameIndex)
|
|||
} while (0);
|
||||
|
||||
_currentKeyFrame = from;
|
||||
_currentKeyFrame->onEnter(to);
|
||||
_currentKeyFrame->onEnter(to, frameIndex);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue