简体   繁体   中英

Presented SKScene changes back to start scene when changing the device orientation

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?

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];
    }
}

我猜你在viewcontroller的viewWillLayoutSubviews方法中运行presentScene而不保护这个方法在某些情况下会重复运行的事实,例如调整视图大小时。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM