junyi00
junyi00

Reputation: 792

Sprite Kit SKSpriteNode drawn outside screen

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

On iPhone 4S, the player is drawn on the screen correctly
But once ran on iPhone 5/5s, the player is drawn above the below the screen, only half of the spritenode can be seen

iPhone 4S:

iPhone 5/5s: (NOTE: the screenshot size is different, the sprite node is in the correct size, but just not at the right position)

Upvotes: 1

Views: 1873

Answers (1)

Mick MacCallum
Mick MacCallum

Reputation: 130222

Sounds like it could be an issue with your choice of SKSceneScaleMode, specifically, it sounds like you may have chosen the resize fill scale mode. Changing this to SKSceneScaleModeAspectFill should be enough to fix this.

Upvotes: 2

Related Questions