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); };