3

Let's say I have a SKScene defined as 320x2000. I will display it on a 320x480 screen so it won't show everything at a given time. Now I want a hero to fly through the scene so he will someday reach the end of the y=2000 scene. For that purpose I have a camera. Implemented like this:

let theCamera = SKCameraNode()

class GameScene: SKScene, SKPhysicsContactDelegate {
    let player: Hero()
    override func didMoveToView(view: SKView) {
        // ...
        scene!.scaleMode = SKSceneScaleMode.ResizeFill
        super.didMoveToView(view)
        // ...
        player.setPosition(view.bounds.size.width / 2, y: view.bounds.size.height / 5)
        // ...
        self.camera = theCamera
        self.camera?.position = player.position
    }

    override func update(currentTime: CFTimeInterval) {
        /* Called before each frame is rendered */

        // Let the player fly and the camera follow him
        player.position.y += 1
        self.camera?.position = player.position
    }
}

What happens is that a) my scene won't start at the bottom of the screen, there is a blank bit of about 30% the size of the screen. b) after a bit of "flying" through the scene the player sprite disappears.

Also, I use this debug code in didMoveToView() AND update():

print("DEBUG: BOUNDS \(self.view?.bounds)")
print("DEBUG: PLAYER \(player.position))")
print("DEBUG: SCENE \(self.scene?.size)")

This is the output from the didMoveToView():

DEBUG: BOUNDS Optional((0.0, 0.0, 320.0, 480.0))
DEBUG: PLAYER (160.0, 96.0))
DEBUG: SCENE Optional((320.0, 2000.0))

And this is the output from the update():

DEBUG: BOUNDS Optional((0.0, 0.0, 320.0, 480.0))
DEBUG: PLAYER (160.0, 96.0))
DEBUG: SCENE Optional((320.0, 480.0))

So: my scene gets resized somehow. I think I am doing something wrong here. I simply want a big (bigger than the device's view) scene to appear partially in the view and let the player be able to fly through the scene to it's end. Also I am using .ResizeFill to let the scene / view adapt to the users device size. Thats why I went with the width of 320 - it should be easily scaled to each other apple device size. But somehow this isn't working on the iPhone 6s+ Simulator.

Thanks for any suggestions what I am doing wrong here with the view / scene / camera setup.

zeeple
  • 5,509
  • 12
  • 43
  • 71
BoA456
  • 341
  • 2
  • 15

0 Answers0