Drakalex Drakalex - 13 days ago 10
Swift Question

SKCameraNode not centered

I'm working with Swift 3, Xcode and SpriteKit

I have a SKCameraNode named cam, and I put a node at the camera's position to check it:

var cam: SKCameraNode!
let cameraNode = SKSpriteNode(imageNamed: "hx")

override func didMove(to view: SKView)
{
cam = SKCameraNode()
camera = cam
addChild(cam)
cam.position = CGPoint(x: playableRect.midWidth, y: playableRect.midHeight)


addChild(cameraNode)
}


And here's what I got :

The red line is the limit of my playableRect.
The white hexagon is the position of the camera. We can clearly see that the camera right in the center of my playableRect as I wanted, but normally this camera should be in the center of the screen, why is it on the left ?
I mean, normally my cameraNode should always be at the center of the screen, it seems logic.

screenshot

Can you help me ?

Answer

Set the scene anchor point to (0.5,0.5)

Comments