How to make camera follow SKNode in Sprite Kit?

Viewed 13021

I want to have background stationary with different objects (sprites and other objects).

Player will be represented by center node that will move around the world. I want to have my camera pinned to central node, e.g. the world should move and the camera should stay stationary.

How do I achieve that?

6 Answers

Using SKCameraNode with SKConstraint in Swift 5.1

let camera = SKCameraNode()
camera.constraints = [.distance(.init(upperLimit: 10), to: node)]
scene.addChild(camera)
scene.camera = camera
Related