How to stop DelayTime action in Sequence action when the Sequence action is running?

Hi all,

currently , I’m facing the problem as follow :

auto delayAction = DelayTime::create(5.0f);
delayAction->setFlags(123);
delayAction->setTag(123);

auto  gameFunction = CallFunc::create([=]() {

	//abc
	//def
});

auto seq = Sequence::createWithTwoActions(delayAction, gameFunction);
seq->setTag(567);

this->runAction(seq);

now , I want to stop the delayAction with tag 123 . I coded :

this->stopActionByTag(123);
this->stopActionsByFlags(123);

But it not work ? My question is how can I stop the delayAction in sequence action ? I don’t want to stop the seq action because , some logic game in gameFunction will work wrong !

I don’t think you can stop a specific action inside a sequence, only the whole sequence.
You can achieve your desired result several ways though:

  1. Whenever you tried to call this->stopActionByTag(123); you can simply stop the full sequence instead. Then call the function that was supposed to go after the delay, ie the gameFunction.
  2. To remove duplicate codes in exampe 1, you can create a function that calls the action sequence with an input parameter of the delay. ex: void createDelayedGameFunction(float delay);. Then in your first call, call this->createDelayedGameFunction(5.0f); and when you stop it call this->createDelayedGameFunction(0);.
  3. There are completely different ways too.

hi @tdebock , thanks for your answer ! I cannot stop the full sequence , and re-init it , because some logic code in gameFunction will work wrong !

That is the only option, if your code will not work the way you want then you need to change accordingly.

1 Like

Step 1 or step 2 I provided should not change anything other than starting the function sooner which is your desired result from what you seem to have said. If you provide more information on what supposed logic will work wrong we might be able to help further, but I don’t seem to see how the steps will change anything.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.