1

Here is my pause method:

- (void)togglePaused
{
    self.paused = !self.paused;
    self.physicsWorld.speed = !self.paused;
}

...where self is the SKScene.

The reason I include the second line is that I noticed that when unpausing, all my physics-enabled nodes were jumping forward immediately, as if the physics has continued running in the background though the scene was paused.

Unfortunately, that does not solve the problem.

How can you pause an SKScene and the SKPhysicsWorld such that, when unpaused, the physics simulation begins where it left off?

SG1
  • 2,871
  • 1
  • 29
  • 41
  • The linked answer http://stackoverflow.com/questions/21593198/pausing-a-sprite-kit-scene?rq=1 suggests that the second line isn't even necessary, but that is not the case in my experience. – SG1 Apr 07 '14 at 23:09

1 Answers1

2

Turns out the second line is in fact not necessary. The problem is that the documentation for didSimulatePhysics is incorrect; it states:

called exactly once per frame, so long as the scene is presented in a view and is not paused

When in fact, it is called regardless of paused status.

Therefore, the basic pause method is correct. Instead, if you are applying modifications to your physics simulation such as I was on every update cycle, then you should check for paused status first like so:

- (void)didSimulatePhysics
    if ( !self.paused ) {
        [parachute.physicsBody applyForce:CGVectorMake(0, 45) atPoint:CGPointMake(parachute.size.width/2, parachute.size.height)];
    }
}

(Unless of course there is a more canon way of applying continuous physics, in which case, the incorrect documentation still stands)

SG1
  • 2,871
  • 1
  • 29
  • 41