How to change SKscene size

2019-02-20 21:25发布

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条回答
Emotional °昔
2楼-- · 2019-02-20 21:43

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

查看更多
登录 后发表回答