0
votes

I have already checked the other answers for pausing my sprite kit game. I want to pause the game after the sprites have loaded, to play a "READY SET GO" animation and then unpause the game.

In viewdidload, I have tried self.view.scene.paused = YES; and self.scene.view.paused = YES; and [self.view.scene setPaused:YES]; and [self.scene.view setPaused:YES]; and none of them work.

I do have some NSTimers being loaded in before the pause, and I have been told that pausing the scene will not pause the timers, BUT, pausing my scene doesn't appear to pause any SKActions, or physics simulations either.

For some reason, [self.heli setPaused:YES]; does pause the heli animation but not the physics simulation for the heli.

Also, my other sprites are added in methods, and they are obstacles that are randomly generated and are added as Children to self

So why isn't pause working?

2

2 Answers

2
votes

You can pause the physics with this:

scene.physicsWorld.speed = 0.0;

Edit based on comment:

You are pausing your node and not your entire scene.

[self.heli setPaused:YES];

This "... determines whether actions on the node and its descendants are processed."

If you are looking to pause your entire scene, then you should use:

self.scene.view.paused = YES;

which will stop all actions and physics simulation.

0
votes

The following is one way you can pause your scene from viewDidLoad. I don't recommend pausing your view in viewDidLoad, but here's how to do it...

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Configure the view.
    SKView * skView = (SKView *)self.view;
    skView.showsFPS = YES;
    skView.showsNodeCount = YES;

    // Create and configure the scene.
    SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
    scene.scaleMode = SKSceneScaleModeAspectFill;

    // The following will NOT pause your SKView because your scene has yet to be presented,
    // so scene.view == nil
    scene.view.paused = YES;

    // This will pause your scene and its contents because the scene has been created
    skView.paused = YES;

    // Present the scene.
    [skView presentScene:scene];
}

I suggest you pause your scene with self.scene.view.paused = YES in your SKScene subclass's didMoveToView (won't work in initWithSize) method. Also, you should consider replacing the NSTimers in your core with SKActions (with waitForDuration, performSelector:onTarget, etc.), since the latter pauses/resumes appropriately when you pause/resume your game.