4
\$\begingroup\$

My game has a sprite representing a character. When the character picks up an item, the sprite should stop moving for a period of time.

I use CCbezier to make the sprite move, like this:

sprite->runaction(x)

Now I want the sprite to stop its current action (moving) and later resume it. I can make the sprite stop by using:

sprite->stopaction(x)

but if I do that, I can't resume the movement. How can I do that?

\$\endgroup\$
1
\$\begingroup\$

You could try this:

[yourSprite pauseSchedulerAndActions]

and to resume

[yourSprite resumeSchedulerAndActions]

Source: SO thread

If that shouldn't work, another option might be:

//pause
[sprite.actionManager pauseTarget:sprite];

//resume
[sprite.actionManager resumeTarget:sprite];
\$\endgroup\$
  • 1
    \$\begingroup\$ [yourSprite pauseSchedulerAndActions] and to resume [yourSprite resumeSchedulerAndActions] These code pause all actions of sprite, i just want pause particular action of sprite, thanks \$\endgroup\$ – user1609578 Jun 6 '14 at 1:34
1
\$\begingroup\$

Yes, cocos2d-x has a built in way to do this. If you want to pause everything the character is doing you can simply use:

  _character->pause();

  _character->resume();


  _scheduler->pauseTarget(_character);

 _scheduler->resumeTarget(_character);
  • NOTE: this also pauses any actions being performed on the character. If you want to continue the actions, but just pause the animation, do this instead:

  • _scheduler is declared in the Node class, so all classes that inherit from it have access to it

.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.