0

i have a Problem with Sprite kit using more than one SKScene. Every time when I change the device orientation, sprite kit presents the first SKScene. When I flip the iPhone, the game scene disappears and the device is showing the menu scene.

How can i fix this?

Banjalucan
  • 115
  • 1
  • 9

2 Answers2

2

Thank You for your help. I solved it with "if ( !skView.scene ) {...}":

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];

    SKView * skView = (SKView *)self.view;

    if ( !skView.scene ) {  // <------- !! 

    SKScene * scene = [MenuScene sceneWithSize:skView.bounds.size];
    scene.scaleMode = SKSceneScaleModeAspectFill;

    [skView presentScene:scene];
    }
}
John Riselvato
  • 12,854
  • 5
  • 62
  • 89
Banjalucan
  • 115
  • 1
  • 9
0

I guess you run presentScene in the viewcontroller's viewWillLayoutSubviews method without safeguarding against the fact that this method will run repeatedly under certain circumstances, such as when the view is resized.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217