Scene size in Xcode 6 / SpriteKit / Swift

前端 未结 1 1918
攒了一身酷
攒了一身酷 2020-12-16 04:26

I\'ve been getting stuck doing what should be really simple stuff in Xcode, I am trying to add a sprite to the scene and for it to sit in the bottom left corner:

<         


        
相关标签:
1条回答
  • 2020-12-16 05:19

    You have to edit the GameViewController:

    Cut everything from viewDidLoad() except super.viewDidLoad()

    Overwrite viewWillLayoutSubviews

    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
    
        if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
            // Configure the view.
            var 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.size = skView.bounds.size
            scene.scaleMode = .AspectFill
    
            skView.presentScene(scene)
        }
    }
    

    Also you should set the scene size as you can see

    scene.size = skView.bounds.size
    

    Hope this helps

    There is also a great Tutorial where this is explained better: http://www.raywenderlich.com/49721/how-to-create-a-breakout-game-using-spritekit (Chapter 1 or 2)

    0 讨论(0)
提交回复
热议问题