Spritekit layout lags when device orientation changes

让人想犯罪 __ 提交于 2020-03-06 09:19:13

问题


Ok, this might be a bit hard to explain since I can't include any video to show you what I mean, but I'll give it a shot.

I have added a SKShapeNode to a scene and when I rotate the device orientation it follows along nicely as expected, positioning itself in the upper left side of the screen whichever way the device is rotated.

But the SKShapeNode "lags" behind, that is, when I rotate to a new orientation, the node remain in the same position for half a second before it is relocated to the new upper left corner. So for instance, in regular portrait mode, the node is in the upper left screen. If I rotate the device to the right (landscape) the node ends up in the upper right side of the screen (because upper left is now in upper right) for half a second before rearranging itself to the new upper left side of the screen.

Hope that made sense. I suspect this has to do with what delegate I position my code in. Here it is:

class GameScene: SKScene {

    override func didMove(to view: SKView) {
        let mySquare = SKShapeNode(rectOf: CGSize(width: 50, height: 50))
        mySquare.fillColor = SKColor.blue
        mySquare.lineWidth = 1

        mySquare.position = CGPoint(x: 0, y: 0)
        self.addChild(mySquare)
    }
}

And the viewController if that helps:

override func viewDidLayoutSubviews() {
    if let view = self.view as! SKView? {
        if let scene = SKScene(fileNamed: "GameScene") {
            scene.scaleMode = .aspectFill
            scene.size = view.frame.size
            scene.anchorPoint = CGPoint(x:0 , y: 1)
            view.presentScene(scene)
        }
            view.ignoresSiblingOrder = true
        }
    }

来源:https://stackoverflow.com/questions/60542976/spritekit-layout-lags-when-device-orientation-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!