From a445148a5e872d3fc2ed0d398485166a3417c961 Mon Sep 17 00:00:00 2001 From: ton Date: Sat, 3 Jan 2015 01:13:57 +0900 Subject: [PATCH] fix problem : JumpTo position is changed each repeat. example: sprite->runAction( RepeatForever::create( Sequence::create( JumpTo::create(1, Vec2(300, 200), 100, 2), MoveTo::create(1, Vec2(100, 200)), nullptr ) ) ); --- cocos/2d/CCActionInterval.cpp | 18 +++++++++++++++++- cocos/2d/CCActionInterval.h | 6 ++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cocos/2d/CCActionInterval.cpp b/cocos/2d/CCActionInterval.cpp index 9104a8b90e..48d9f8b3f0 100644 --- a/cocos/2d/CCActionInterval.cpp +++ b/cocos/2d/CCActionInterval.cpp @@ -1450,6 +1450,22 @@ JumpTo* JumpTo::create(float duration, const Vec2& position, float height, int j return jumpTo; } +bool JumpTo::initWithDuration(float duration, const Vec2& position, float height, int jumps) +{ + CCASSERT(jumps>=0, "Number of jumps must be >= 0"); + + if (ActionInterval::initWithDuration(duration) && jumps>=0) + { + _endPosition = position; + _height = height; + _jumps = jumps; + + return true; + } + + return false; +} + JumpTo* JumpTo::clone() const { // no copy constructor @@ -1468,7 +1484,7 @@ JumpTo* JumpTo::reverse() const void JumpTo::startWithTarget(Node *target) { JumpBy::startWithTarget(target); - _delta = Vec2(_delta.x - _startPosition.x, _delta.y - _startPosition.y); + _delta = Vec2(_endPosition.x - _startPosition.x, _endPosition.y - _startPosition.y); } // Bezier cubic formula: diff --git a/cocos/2d/CCActionInterval.h b/cocos/2d/CCActionInterval.h index 7957ea9a9e..5388952983 100644 --- a/cocos/2d/CCActionInterval.h +++ b/cocos/2d/CCActionInterval.h @@ -604,6 +604,12 @@ CC_CONSTRUCTOR_ACCESS: JumpTo() {} virtual ~JumpTo() {} + /** initializes the action */ + bool initWithDuration(float duration, const Vec2& position, float height, int jumps); + +protected: + Vec2 _endPosition; + private: CC_DISALLOW_COPY_AND_ASSIGN(JumpTo); };