Sprite Kit SKSpriteNode在屏幕外绘制

时间:2014-06-16 13:38:07

标签: ios sprite-kit swift

GameScene.swift:

override func didMoveToView(view: SKView) {

    self.backgroundColor = SKColor.whiteColor()

    self.player = SKSpriteNode(imageNamed:"player")
    self.player.position = CGPointMake(100, 100)
    self.player.size = CGSize(width: self.player.size.width*2, height: self.player.size.height*2)
    self.addChild(self.player)

}

GameViewController.swift:

override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()

    if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
        // Configure the view.
        let skView = self.view as SKView
        skView.showsFPS = false
        skView.showsNodeCount = false

        /* 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)
    }
}

在iPhone 4S上,播放器正确地在屏幕上绘制 但是一旦在iPhone 5 / 5s上运行,播放器被绘制在屏幕下方,只能看到spritenode的一半

iPhone 4S:

iPhone 5 / 5s :(注意:屏幕截图大小不同,精灵节点尺寸正确,但不在正确的位置)

1 个答案:

答案 0 :(得分:2)

听起来这可能是您选择SKSceneScaleMode的问题,具体而言,听起来您可能选择了调整大小填充比例模式。将此更改为SKSceneScaleModeAspectFill应足以解决此问题。