Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've had a similar problem with playing audio (though I'm not using audio in an SKAction node) with the same background crash as a result.</p> <p>I tried to solve this by setting the <code>paused</code> property of my SKScene to <code>YES</code>, but when audio is playing there appears to be a bug in SpriteKit. In this situation, the update method actually gets called after paused is set to YES. Here is my update code:</p> <pre><code>- (void)update:(CFTimeInterval)currentTime { /* Called before each frame is rendered */ if (self.paused) { // Apple bug? NSLog(@"update: called while SKView.paused == YES!"); return; } // update! [_activeLayer update]; } </code></pre> <p>When that NSLog is traced out, the app will then crash with the GL error.</p> <p>The only way I've found to solve it is quite heavy handed. I have to remove and deallocate my entire SKView when entering the background.</p> <p>In <code>applicationDidEnterBackground</code> I call a function in my ViewController that does this:</p> <pre><code>[self.playView removeFromSuperview]; </code></pre> <p>Ensure that you do not have any strong references to the SKView as it must be deallocated for this to work.</p> <p>In <code>applicationWillEnterForeground</code> I call a function that rebuilds my SKView like this:</p> <pre><code>CGRect rect = self.view.frame; if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) { CGFloat temp = rect.size.width; rect.size.width = rect.size.height; rect.size.height = temp; } SKView *skView = [[SKView alloc] initWithFrame:rect]; skView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; [self.view insertSubview:skView atIndex:0]; self.playView = skView; // Create and configure the scene. self.myScene = [CustomScene sceneWithSize:skView.bounds.size]; self.myScene.scaleMode = SKSceneScaleModeResizeFill; // Present the scene. [skView presentScene:self.myScene]; </code></pre> <p>Yeah, this feels like a total hack, but I think there is a bug in SpriteKit.</p> <p>I hope this helps.</p> <p><strong>EDIT</strong></p> <p>Great accepted answer above. Unfortunately it doesn't work for me because I am using Audio Queues and need music to continue playing when my app is in the background.</p> <p>Still waiting for a fix from Apple.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload