From be8a158bd71a243492b79b75b938e6b6925c7c40 Mon Sep 17 00:00:00 2001 From: geron-cn Date: Tue, 20 Oct 2015 15:49:12 +0800 Subject: [PATCH] fix bug: #23532 AnchorPointFrame animation performance diffrent with cocos studio --- .../ActionTimeline/CCActionTimelineCache.cpp | 29 +++++++++++++------ .../cocostudio/ActionTimeline/CCFrame.cpp | 14 ++++++++- .../cocostudio/ActionTimeline/CCFrame.h | 5 +++- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp index d2d04c2973..db9ed09714 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp @@ -478,17 +478,23 @@ inline ActionTimeline* ActionTimelineCache::createActionWithDataBuffer(const coc action->addAnimationInfo(info); } - auto timelines = nodeAction->timeLines(); - int timelineLength = timelines->size(); + auto timeLines = nodeAction->timeLines(); + int timelineLength = timeLines->size(); + std::multimap properTimelineMap;// order the timelines depends property name for (int i = 0; i < timelineLength; i++) { - auto timelineFlatBuf = timelines->Get(i); + auto timelineFlatBuf = timeLines->Get(i); Timeline* timeline = loadTimelineWithFlatBuffers(timelineFlatBuf); - if (timeline) - action->addTimeline(timeline); + { + properTimelineMap.insert(std::make_pair(timelineFlatBuf->property()->c_str(), timeline)); + } } + for (const auto& properTimelinePair : properTimelineMap) + { + action->addTimeline(properTimelinePair.second); + } return action; } @@ -969,17 +975,22 @@ ActionTimeline* ActionTimelineCache::createActionWithFlatBuffersForSimulator(con auto timeLines = nodeAction->timeLines(); int timelineLength = timeLines->size(); + std::multimap properTimelineMap;// order the timelines depends property name for (int i = 0; i < timelineLength; i++) { auto timelineFlatBuf = timeLines->Get(i); Timeline* timeline = loadTimelineWithFlatBuffers(timelineFlatBuf); - if (timeline) - action->addTimeline(timeline); + { + properTimelineMap.insert(std::make_pair(timelineFlatBuf->property()->c_str(), timeline)); + } + } + + for (const auto& properTimelinePair : properTimelineMap) + { + action->addTimeline(properTimelinePair.second); } - fbs->deleteFlatBufferBuilder(); - return action; } diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.cpp index 44ad3c0a5a..1cbc10f4b6 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.cpp @@ -506,7 +506,10 @@ void AnchorPointFrame::onEnter(Frame *nextFrame, int currentFrameIndex) { return; } - + if (_tween) + { + _betweenAnchorPoint = static_cast(nextFrame)->_anchorPoint - _anchorPoint; + } _node->setAnchorPoint(_anchorPoint); } @@ -521,6 +524,15 @@ Frame* AnchorPointFrame::clone() return frame; } +void AnchorPointFrame::onApply(float percent) +{ + if ((nullptr != _node) && (_betweenAnchorPoint.x != 0 || _betweenAnchorPoint.y != 0)) + { + auto applyAnchorP = _betweenAnchorPoint * percent + _anchorPoint; + _node->setAnchorPoint(applyAnchorP); + } +} + // InnerActionFrame diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.h b/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.h index 60344cb8af..7abb546707 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.h +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.h @@ -260,7 +260,10 @@ public: inline cocos2d::Point getAnchorPoint() const { return _anchorPoint; } protected: - cocos2d::Point _anchorPoint; + virtual void onApply(float percent) override; + + cocos2d::Vec2 _betweenAnchorPoint; + cocos2d::Vec2 _anchorPoint; };