Swift SpriteKit get visible frame size

孤者浪人 提交于 2019-12-06 15:48:31

Adding this bit of code to the GameViewController seems to have fixed the issue.

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

Thank you @ABakerSmith for pointing me in the right direction.

I tried with your code and setting the size of the scene fixed the issue. If you're unarchiving the scene, its size will be the size set in the sks file. Therefore you need to set the size of the scene to the size of your SKView.

if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
    scene.size = skView.frame.size
    skView.presentScene(scene)
}

or in didMoveToView of your SKScene subclass:

override func didMoveToView(view: SKView) {
     super.didMoveToView(view)
     self.size = view.frame.size
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!