Stephen Haney

SKSpriteNodes anchorPoint in Swift and SpriteKit

Note: This is a free excerpt from my new book, Game Development with Swift. If you like this post, you’ll love the book! The book walks you through the creation of a 2D iOS game from start to publication on the App Store. So far, I’ve received nothing but great feedback from readers. Check out my new Swift SpriteKit book on Amazon

SpriteKit uses a grid of points to position nodes. In this grid, the bottom left corner of the scene is (0,0), with a positive X-axis to the right and a positive Y-axis to the top. Similarly, on the individual sprite level, (0,0) refers to the bottom left corner of the sprite, while (1,1) refers to the top right corner.

Alignment with Anchor Points

Each sprite has an anchor point property, or an origin. The anchorPoint property allows you to choose which part of the sprite aligns to the sprite’s overall position.

The default anchor point is (0.5,0.5), so new SKSpriteNodes center perfectly on their position.