简体   繁体   中英

SpriteKit GameScene Rotation Bug

I have been having a problem recently with this app which I encountered whilst trying to make the app universal and portrait orientation as well (the previous version was landscape on iPhone only). Now the app will open in portrait and look correct, but it is still in portrait when the device is rotated.

应用程式错误

This is currently all the code I have for rotating the device (which works):

override func shouldAutorotate() -> Bool {
    return true
}

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return .AllButUpsideDown
    } else {
        return .All
    }
}

However, this only rotates the device and not the actual GameScene within which my game is contained. If the app is launched from a landscape homescreen, the game will stay in landscape.

For testing purposes, I can quit and relaunch the app from the simulator homescreen and the game will work perfectly again until the device is rotated .

How do I consistently present the GameScene in the correct orientation?

You'll need to make sure that your SKView that holds your SKScene is set to match the bounds of it's containing frame. You can do this with Autolayout either in InterfaceBuilder or through code.

As Good Doug said try setting the skView size.

In code you would load the first scene from the gameViewController like so. (This works if you dont use the scene sks files)

    let skView = view as! SKView!
    let scene = StartScene(size: skView.bounds.size)

    skView.ignoresSiblingOrder = true
    scene.scaleMode = .AspectFill

    skView.presentScene(scene)

Also its seems like a very bad idea to make a game run in portrait and landscape, it will cause you so many problems I wouldn't even try.

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