How to change SKscene size

懵懂的女人 提交于 2019-12-19 11:29:17

问题


every time i run my app in my simulator the view scale always comes out to 768,1024 how do you change this to 1024,768. here is the default size code class GameViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    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

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

        skView.presentScene(scene)
    }
}

回答1:


1) If you use .sks files (the spriteKit visual editor)

Just go to the GameScene.sks file (not swift) in you project where you can change the scene size in the inspector on the right.

You can check this article here where they show this if you scroll down a tiny bit. Its a good tutorial you should ready if you plan on working with the visual editor.

https://www.raywenderlich.com/118225/introduction-sprite-kit-scene-editor

2) Not using .sks files, loading scenes in code

If you dont use .sks files you can delete the GameScene.sks file and load the scene like so.

 override func viewDidLoad() {
super.viewDidLoad()

    // Configure the view.
    guard let skView = self.view as? SKView else { return }

    let scene = GameScene(size: CGSize(width: 1920, height: 1080))

    skView.showsFPS = true
    skView.showsNodeCount = true

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

    scene.scaleMode = .AspectFill

    skView.presentScene(scene)
  }

Hope this helps



来源:https://stackoverflow.com/questions/36255593/how-to-change-skscene-size

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