From e7de544231261cc5a319914532bd55e347d13192 Mon Sep 17 00:00:00 2001 From: "kaile.yin" Date: Thu, 23 Oct 2014 17:37:18 +0800 Subject: [PATCH 1/2] 1.fixed frame event may forword emit --- .../cocostudio/ActionTimeline/CCFrame.cpp | 37 ++++++++++--------- .../cocostudio/ActionTimeline/CCFrame.h | 26 ++++++------- .../cocostudio/ActionTimeline/CCTimeLine.cpp | 6 +-- 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.cpp index f1dc53a7af..a959680716 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.cpp @@ -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(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(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(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(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(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(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); diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.h b/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.h index 10b72d36a4..2be52adfb4 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.h +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.h @@ -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;} diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCTimeLine.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCTimeLine.cpp index cac7ff5178..e0832362ec 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCTimeLine.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCTimeLine.cpp @@ -202,7 +202,7 @@ void Timeline::binarySearchKeyFrame(int frameIndex) if(needEnterFrame || _currentKeyFrame != from) { _currentKeyFrame = from; - _currentKeyFrame->onEnter(to); + _currentKeyFrame->onEnter(to, frameIndex); } } @@ -254,7 +254,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); @@ -266,7 +266,7 @@ void Timeline::updateCurrentKeyFrame(int frameIndex) } while (0); _currentKeyFrame = from; - _currentKeyFrame->onEnter(to); + _currentKeyFrame->onEnter(to, frameIndex); } } From 0f184a49820f09a035efcfd1f8eb480a89bc06b5 Mon Sep 17 00:00:00 2001 From: "kaile.yin" Date: Thu, 23 Oct 2014 17:38:04 +0800 Subject: [PATCH 2/2] add arriving last frame event --- .../ActionTimeline/CCActionTimeline.cpp | 16 ++++++++++++++++ .../cocostudio/ActionTimeline/CCActionTimeline.h | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.cpp index feb015a36a..e4dcd1da2b 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.cpp @@ -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 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++) { diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.h b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.h index 321b1136fa..76a3299d78 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.h +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimeline.h @@ -129,6 +129,10 @@ public: void setFrameEventCallFunc(std::function listener); void clearFrameEventCallFunc(); + /** Last frame callback will call when arriving last frame */ + void setLastFrameCallFunc(std::function listener); + void clearLastFrameCallFunc(); + /** Inherit from Action. */ /** Returns a clone of ActionTimeline */ @@ -163,6 +167,7 @@ protected: bool _loop; std::function _frameEventListener; + std::function _lastFrameListener; }; NS_TIMELINE_END