diff --git a/cocos2dx/actions/CCActionInterval.cpp b/cocos2dx/actions/CCActionInterval.cpp index 66ccbe88f8..f9c384e1f3 100644 --- a/cocos2dx/actions/CCActionInterval.cpp +++ b/cocos2dx/actions/CCActionInterval.cpp @@ -2201,8 +2201,11 @@ TargetedAction* TargetedAction::clone() const TargetedAction* TargetedAction::reverse(void) const { - // no reverse for this action, just clone it - return this->clone(); + // just reverse the internal action + auto a = new TargetedAction(); + a->initWithTarget(_forcedTarget, _action->reverse()); + a->autorelease(); + return a; } void TargetedAction::startWithTarget(Node *target) diff --git a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp index 2f1f0b3907..23a6ba6791 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp @@ -39,6 +39,7 @@ static std::function createFunctions[] = { CL(ActionOrbit), CL(ActionFollow), CL(ActionTargeted), + CL(ActionTargetedReverse), CL(ActionMoveStacked), CL(ActionMoveJumpStacked), CL(ActionMoveBezierStacked), @@ -1335,6 +1336,37 @@ std::string ActionTargeted::subtitle() return "Action that runs on another target. Useful for sequences"; } + +void ActionTargetedReverse::onEnter() +{ + ActionsDemo::onEnter(); + centerSprites(2); + + + auto jump1 = JumpBy::create(2,Point::ZERO,100,3); + auto jump2 = jump1->clone(); + auto rot1 = RotateBy::create(1, 360); + auto rot2 = rot1->clone(); + + auto t1 = TargetedAction::create(_kathia, jump2); + auto t2 = TargetedAction::create(_kathia, rot2); + + auto seq = Sequence::create(jump1, t1->reverse(), rot1, t2->reverse(), NULL); + auto always = RepeatForever::create(seq); + + _tamara->runAction(always); +} + +std::string ActionTargetedReverse::title() +{ + return "ActionTargetedReverse"; +} + +std::string ActionTargetedReverse::subtitle() +{ + return "Action that runs reversely on another target. Useful for sequences"; +} + //#pragma mark - ActionStacked void ActionStacked::onEnter() diff --git a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h index facb2a01cc..6c418bb15c 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h +++ b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h @@ -289,6 +289,14 @@ public: virtual std::string subtitle(); }; +class ActionTargetedReverse : public ActionsDemo +{ +public: + virtual void onEnter(); + virtual std::string title(); + virtual std::string subtitle(); +}; + class ActionStacked : public ActionsDemo { public: