Swift SpriteKit edgeLoopFromRect Issue

痞子三分冷 提交于 2019-12-04 09:25:18
Whirlwind

You are probably on the right track about .sks file. When scene is loaded from the .sks file the default size is 1024x768. Now you can dynamically set that based on the view size. So, swap your viewDidLoad with viewWillLayoutSubviews like this:

override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()

    if let scene = GameScene(fileNamed:"GameScene") {
        // Configure the view.
        let skView = self.view as! SKView
        skView.showsFPS = true
        skView.showsNodeCount = true

        /* Sprite Kit applies additional optimizations to improve rendering performance */
        skView.ignoresSiblingOrder = true

        //Because viewWillLayoutSubviews might be called multiple times, check if scene is already initialized
         if(skView.scene == nil){

            /* Set the scale mode to scale to fit the window */
            scene.scaleMode = .AspectFill
            scene.size = skView.bounds.size

            skView.presentScene(scene)
        }
    }
}

There are many posts on SO about differences between viewDidLoad and viewWillLayoutSubviews, so I will skip that in my answer.

Hope this helps.

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