mirror of https://github.com/axmolengine/axmol.git
Merge pull request #7558 from newnon/v3_actions_by_tag_improvements
stopAllActionsByTag && removeAllActionsByTag
This commit is contained in:
commit
681c3c06f1
|
@ -287,6 +287,34 @@ void ActionManager::removeActionByTag(int tag, Node *target)
|
|||
}
|
||||
}
|
||||
|
||||
void ActionManager::removeAllActionsByTag(int tag, Node *target)
|
||||
{
|
||||
CCASSERT(tag != Action::INVALID_TAG, "");
|
||||
CCASSERT(target != nullptr, "");
|
||||
|
||||
tHashElement *element = nullptr;
|
||||
HASH_FIND_PTR(_targets, &target, element);
|
||||
|
||||
if (element)
|
||||
{
|
||||
auto limit = element->actions->num;
|
||||
for (int i = 0; i < limit;)
|
||||
{
|
||||
Action *action = (Action*)element->actions->arr[i];
|
||||
|
||||
if (action->getTag() == (int)tag && action->getOriginalTarget() == target)
|
||||
{
|
||||
removeActionAtIndex(i, element);
|
||||
--limit;
|
||||
}
|
||||
else
|
||||
{
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get
|
||||
|
||||
// XXX: Passing "const O *" instead of "const O&" because HASH_FIND_IT requries the address of a pointer
|
||||
|
|
|
@ -93,6 +93,9 @@ public:
|
|||
/** Removes an action given its tag and the target */
|
||||
void removeActionByTag(int tag, Node *target);
|
||||
|
||||
/** Removes all actions given its tag and the target */
|
||||
void removeAllActionsByTag(int tag, Node *target);
|
||||
|
||||
/** Gets an action given its tag an a target
|
||||
@return the Action the with the given tag
|
||||
*/
|
||||
|
|
|
@ -1440,6 +1440,12 @@ void Node::stopActionByTag(int tag)
|
|||
_actionManager->removeActionByTag(tag, this);
|
||||
}
|
||||
|
||||
void Node::stopAllActionsByTag(int tag)
|
||||
{
|
||||
CCASSERT( tag != Action::INVALID_TAG, "Invalid tag");
|
||||
_actionManager->removeAllActionsByTag(tag, this);
|
||||
}
|
||||
|
||||
Action * Node::getActionByTag(int tag)
|
||||
{
|
||||
CCASSERT( tag != Action::INVALID_TAG, "Invalid tag");
|
||||
|
|
|
@ -1128,6 +1128,13 @@ public:
|
|||
*/
|
||||
void stopActionByTag(int tag);
|
||||
|
||||
/**
|
||||
* Removes all actions from the running action list by its tag.
|
||||
*
|
||||
* @param tag A tag that indicates the action to be removed.
|
||||
*/
|
||||
void stopAllActionsByTag(int tag);
|
||||
|
||||
/**
|
||||
* Gets an action from the running action list by its tag.
|
||||
*
|
||||
|
|
|
@ -15,7 +15,7 @@ Layer* restartActionManagerAction();
|
|||
|
||||
static int sceneIdx = -1;
|
||||
|
||||
#define MAX_LAYER 5
|
||||
#define MAX_LAYER 6
|
||||
|
||||
Layer* createActionManagerLayer(int nIndex)
|
||||
{
|
||||
|
@ -25,7 +25,8 @@ Layer* createActionManagerLayer(int nIndex)
|
|||
case 1: return new LogicTest();
|
||||
case 2: return new PauseTest();
|
||||
case 3: return new StopActionTest();
|
||||
case 4: return new ResumeTest();
|
||||
case 4: return new StopAllActionsTest();
|
||||
case 5: return new ResumeTest();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
@ -267,6 +268,56 @@ std::string StopActionTest::subtitle() const
|
|||
return "Stop Action Test";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// RemoveTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
void StopAllActionsTest::onEnter()
|
||||
{
|
||||
ActionManagerTest::onEnter();
|
||||
|
||||
auto l = Label::createWithTTF("Should stop scale & move after 4 seconds but keep rotate", "fonts/Thonburi.ttf", 16.0f);
|
||||
addChild(l);
|
||||
l->setPosition( Vec2(VisibleRect::center().x, VisibleRect::top().y - 75) );
|
||||
|
||||
auto pMove1 = MoveBy::create(2, Vec2(200, 0));
|
||||
auto pMove2 = MoveBy::create(2, Vec2(-200, 0));
|
||||
auto pSequenceMove = Sequence::createWithTwoActions(pMove1, pMove2);
|
||||
auto pRepeatMove = RepeatForever::create(pSequenceMove);
|
||||
pRepeatMove->setTag(kTagSequence);
|
||||
|
||||
auto pScale1 = ScaleBy::create(2, 1.5);
|
||||
auto pScale2 = ScaleBy::create(2, 1.0/1.5);
|
||||
auto pSequenceScale = Sequence::createWithTwoActions(pScale1, pScale2);
|
||||
auto pRepeatScale = RepeatForever::create(pSequenceScale);
|
||||
pRepeatScale->setTag(kTagSequence);
|
||||
|
||||
auto pRotate = RotateBy::create(2, 360);
|
||||
auto pRepeatRotate = RepeatForever::create(pRotate);
|
||||
|
||||
auto pChild = Sprite::create(s_pathGrossini);
|
||||
pChild->setPosition( VisibleRect::center() );
|
||||
|
||||
addChild(pChild, 1, kTagGrossini);
|
||||
pChild->runAction(pRepeatMove);
|
||||
pChild->runAction(pRepeatScale);
|
||||
pChild->runAction(pRepeatRotate);
|
||||
this->scheduleOnce((SEL_SCHEDULE)&StopAllActionsTest::stopAction, 4);
|
||||
}
|
||||
|
||||
void StopAllActionsTest::stopAction(float time)
|
||||
{
|
||||
auto sprite = getChildByTag(kTagGrossini);
|
||||
sprite->stopAllActionsByTag(kTagSequence);
|
||||
}
|
||||
|
||||
std::string StopAllActionsTest::subtitle() const
|
||||
{
|
||||
return "Stop All Action Test";
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// ResumeTest
|
||||
|
|
|
@ -54,6 +54,14 @@ public:
|
|||
void stopAction();
|
||||
};
|
||||
|
||||
class StopAllActionsTest : public ActionManagerTest
|
||||
{
|
||||
public:
|
||||
virtual std::string subtitle() const override;
|
||||
virtual void onEnter() override;
|
||||
void stopAction(float time);
|
||||
};
|
||||
|
||||
class ResumeTest : public ActionManagerTest
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue