From 97f6e11f0da7a9e2666dc66657d84bef43a07963 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Thu, 1 Aug 2013 10:07:40 +0800 Subject: [PATCH 1/2] issue #2423 : change TargetedAction::reverse() function from just cloning to reversing the internal action --- cocos2dx/actions/CCActionInterval.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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) From 9a9d0b9defd8a29625fa0d260c2a0dc24724c9fc Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Thu, 1 Aug 2013 10:28:18 +0800 Subject: [PATCH 2/2] closed #2423: add ActionTargetedReverse test case --- .../Classes/ActionsTest/ActionsTest.cpp | 32 +++++++++++++++++++ .../TestCpp/Classes/ActionsTest/ActionsTest.h | 8 +++++ 2 files changed, 40 insertions(+) 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: