Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpriteKit: SKScene Freeze when modal view pesented

I'm having the following issue with SpriteKit. I'm presenting a modal viewController from another viewController which view is a SKView, the problem is that the SKScene in the SKView freezes when i dismiss the modal viewController, and it unfreezes if I present and dismiss the modal view again. It's toggling...

The weird thing is that when the scene unfreezes I can see that animations continued in the background as the sprites are in different positions than they where before the freeze.

To make things weirder, it only happens when testing in the actual device, not in the simulator.

I saw this question: iAds and SpriteKit: SKScene Freeze on fullscreen exit on device only but it has no answer and the problem is when using iAds. I've read in other forums that it can be solved by removing self.canDisplayBannerAds = YES, but I'm not using iAds at all.

Please help, i'm desperate.

like image 218
OscarVGG Avatar asked Feb 14 '23 00:02

OscarVGG


1 Answers

I had almost the same problem, this link helped me Go from SKView back to UIView

The point is to make your skView a subview of an UIView and then make an IBOutlet that link to your skView.

That work with and without iAd Banner (in my case I made the banner a subview+iboutlet as well)

How to reproduce the effect:

Preparation:

  1. Create a new SpriteKit project
  2. Open Main_Iphone.storyboard
  3. Add (drag/drop) a Tab bar controller
  4. Delete Viewcontroller Item1
  5. Create a Viewcontroller Segue from the tab bar controller to the original (Apple) viewcontroller (the one with the skview)
  6. In View Controller properties click Is initial View Controller
  7. Run on actual device

Action:

  1. Go to Item tab click to launch Plane's animation
  2. Click on Item 2
  3. Click back to Item tab => Plane is Frozen
  4. Click several time => nothing happen
  5. Click on Item 2 and back to Item => Several Planes moving (toggling effect)

How to Solve the problem:

  1. Drag a view onto the original (Apple) skview You should now have a parent/child link in the object navigator pane (left)
  2. Permute the Custom Class properties, so that child is now SkView and Parent is UIView
  3. Show the assistant editor with storyboard and ViewController.h

  4. control-drag the skview to the interface and create an IBOutlet named skView

    ViewController.h:

    #import <UIKit/UIKit.h>
    #import <SpriteKit/SpriteKit.h>
    
    @interface ViewController : UIViewController
    @property (strong, nonatomic) IBOutlet UIView *skView;
    
    @end
    
  5. in ViewController.m comment line 19 and replace skView by self.skView

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        // Configure the view.
        //SKView * skView = (SKView *)self.view;
        self.skView.showsFPS = YES;
        self.skView.showsNodeCount = YES;
    
        // Create and configure the scene.
        SKScene * scene = [MyScene sceneWithSize:self.skView.bounds.size];
        scene.scaleMode = SKSceneScaleModeAspectFill;
    
        // Present the scene.
        [self.skView presentScene:scene];
    }
    
  6. Run and now no more freeze

Regards

like image 65
plusdepseudo Avatar answered Feb 16 '23 03:02

plusdepseudo