From 5b0e2f0304d48e3936a25d3099455755ccb25573 Mon Sep 17 00:00:00 2001 From: "kaile.yin" Date: Fri, 17 Oct 2014 20:43:01 +0800 Subject: [PATCH] fixed emit last frame several times --- .../cocostudio/ActionTimeline/CCFrame.cpp | 7 ++++++ .../cocostudio/ActionTimeline/CCFrame.h | 4 ++++ .../cocostudio/ActionTimeline/CCTimeLine.cpp | 23 +++++++++++-------- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.cpp index d0f698d419..f1dc53a7af 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.cpp @@ -36,6 +36,7 @@ NS_TIMELINE_BEGIN Frame::Frame() : _frameIndex(0) , _tween(true) + , _enterWhenPassed(false) , _timeline(nullptr) , _node(nullptr) { @@ -554,6 +555,7 @@ EventFrame* EventFrame::create() EventFrame* frame = new (std::nothrow) EventFrame(); if (frame) { + frame->init(); frame->autorelease(); return frame; } @@ -561,6 +563,11 @@ EventFrame* EventFrame::create() return nullptr; } +void EventFrame::init() +{ + _enterWhenPassed = true; +} + EventFrame::EventFrame() : _event("") { diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.h b/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.h index 46022f7f0e..10b72d36a4 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.h +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.h @@ -54,6 +54,8 @@ public: virtual void setTween(bool tween) { _tween = tween; } virtual bool isTween() const { return _tween; } + virtual bool isEnterWhenPassed() { return _enterWhenPassed; } + virtual void onEnter(Frame *nextFrame) = 0; virtual void apply(float percent) {} @@ -68,6 +70,7 @@ protected: unsigned int _frameIndex; bool _tween; + bool _enterWhenPassed; Timeline* _timeline; cocos2d::Node* _node; @@ -300,6 +303,7 @@ class CC_STUDIO_DLL EventFrame : public Frame { public: static EventFrame* create(); + void init(); EventFrame(); diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCTimeLine.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCTimeLine.cpp index db0e78af9b..4f4719db96 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCTimeLine.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCTimeLine.cpp @@ -210,10 +210,9 @@ void Timeline::updateCurrentKeyFrame(int frameIndex) } else if(frameIndex >= _frames.at(length - 1)->getFrameIndex()) { - from = to = _frames.at(length - 1); - _currentKeyFrameIndex = _frames.at(length - 1)->getFrameIndex(); - _betweenDuration = 0; - break; + int lastFrameIndex = _frames.at(length - 1)->getFrameIndex(); + if(_currentKeyFrameIndex >= lastFrameIndex) + return; } do @@ -229,14 +228,20 @@ void Timeline::updateCurrentKeyFrame(int frameIndex) } to = _frames.at(_toIndex); - - if (frameIndex == from->getFrameIndex()) - { + if(from->getFrameIndex() == 19) + int a = 0; + if(frameIndex == from->getFrameIndex()) break; - } + if(frameIndex > from->getFrameIndex() && frameIndex < to->getFrameIndex()) + break; + if(from->isEnterWhenPassed()) + from->onEnter(to); } - while (frameIndex < from->getFrameIndex() || frameIndex >= to->getFrameIndex()); + while (true); + if(_fromIndex == length) + to = from; + _betweenDuration = to->getFrameIndex() - from->getFrameIndex(); } while (0);