4

I'm trying to implement a pause function to my game. So far I've got it to work by setting my sprites speed to "0". But the sprites on which I've applied easing behave strange when pause button (speed = 0) is pressed; Their translation - Both location and rotation jump to another time/place in the action both when speed is set to "0" as well as when they are reset to "1". I would very much appreciate some input on this issue - Either a fix for my code or a better way of doing it :)

My sprite's movement code:

SKAction* _movePlayerUp = [SKAction moveToY:200 duration:3];
movePlayerUp.timingMode = SKActionTimingEaseOut;
[_playerSprite runAction: movePlayerUp];

Function to enable pause:

  _playerSprite.speed = 0;

Function to disable pause:

  _playerSprite.speed = 1;

Thank you in advance!

Regards, Espen

ezprado
  • 53
  • 4

1 Answers1

2

LearnCocos2D is right (because when is Setffen Itterheim wrong?) in saying that the correct way to pause your _playerSprite object is by setting the paused property to YES. If you're looking to pause your entire scene though, the best way to do it is to set the paused property on the SKView that contains the running SKScene. The speed property on an SKAction is used to adjust the timing on actions, not really to start or stop them.

doctorBroctor
  • 2,018
  • 1
  • 14
  • 17
  • OP was setting the speed of the node (property of SKNode) not the action. – 0x141E Aug 06 '14 at 21:47
  • Thanks! The reason I don't pause SKView is that I have an animation when Pause is enabled and an countdown when Pause is disabled. Hope that makes sense :) – ezprado Aug 06 '14 at 21:48
  • That makes sense. What you can do then is have everything you want paused in a container node and pause that node (all SKNodes have a paused property.) Then run your animation over it – doctorBroctor Aug 06 '14 at 21:51