27
@property (SK_NONATOMIC_IOSONLY, getter = isPaused) BOOL paused;

I found this line of code that I could add into my project, how would I pause my whole game?

For example:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
for (UITouch *touch in touches)
{
    SKSpriteNode *pause = (SKSpriteNode*)[self childNodeWithName:@"pause"];
    CGPoint location = [touch locationInNode:self];
    // NSLog(@"** TOUCH LOCATION ** \nx: %f / y: %f", location.x, location.y);

    if([pause containsPoint:location])
    {
        NSLog(@"PAUSE GAME HERE SOMEHOW");
    }
}

}

As you can see, I have the button set up. When i select it, how would I pause the whole scene? And then resume it when someone hits a resume button.

OK SO I got some advice to call

  self.scene.view.paused = YES;

except here is the problem, in my app delegate

- (void)applicationWillResignActive:(UIApplication *)application{


SKView *view = (SKView *)self.window.rootViewController.view;
view.paused = YES;}

and

- (void)applicationDidBecomeActive:(UIApplication *)application{

    SKView *view = (SKView *)self.window.rootViewController.view;
    view.paused = NO;

I make it a type SKView, when it is actually an SKScene. Anyway to fix this? Do you suggest that I make all my scenes into views by retyping all the code?

temp
  • 639
  • 1
  • 8
  • 22
  • You seem to be confused about Scenes and Views. You play your skscene ON an skview. Pausing either the SKScene or the SKView pauses the game, but as Andrey suggests below is the best method. – ZeMoon May 31 '14 at 05:32

3 Answers3

64

Use SKView's isPaused property:

Swift:

scene.view?.isPaused = true

Objective C:

self.scene.view.isPaused = YES;

This will stop all actions and physics simulation.

Björn Hjorth
  • 2,459
  • 5
  • 25
  • 31
Andrey Gordeev
  • 30,606
  • 13
  • 135
  • 162
2

Use Scene to Paused Functionality

self.scene?.view?.paused = true
Whirlwind
  • 14,286
  • 11
  • 68
  • 157
Raksha Saini
  • 604
  • 12
  • 28
0

Property 'paused' has been renamed to 'isPaused'

scene?.view?.isPaused = true
Björn Hjorth
  • 2,459
  • 5
  • 25
  • 31