Set Position, Coordinates, and Anchor Points

When you add nodes to a scene and set their position, knowing how the coordinate system works in SpriteKit is key to avoiding frustration.

In SpriteKit, the bottom-left corner of the unit coordinate system is located at (x: 0, y: 0) and the top-right corner is located at (x: 1, y: 1), as shown in the following illustration:

images/CreatingScenesWithSpritesAndNodes/spritekit-anchorPoint.png

When you position a sprite node, you need to consider its anchorPoint property, which defaults to (x: 0.5, y: 0.5).

Look at the sprite node in the following image; its position property is set to (x: 0, y: 0). Notice how changing the anchorPoint can affect the node’s position. ...

Get Apple Game Frameworks and Technologies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.