Game Development Reference
In-Depth Information
Figure 2-9
.
SKSpriteNode's anchor point unit coordinate system
This figure shows an
SKSpriteNode
's anchor point coordinate system. Notice the dot
at position (0.5, 0.5). This is the default anchor point. Take a look at
Figure 2-10
to see
some common anchor points.
Figure 2-10
.
An SKSpriteNode's some example anchor points
In this figure there are four common anchor points as they relate to the sprites they are ap-
plied to. Looking at these examples, you can see that if you want to position the
play-
erNode
at the top-rightmost position of the scene and still have the entire
spriteNode
visible in the scene, then you would need to set the sprite's
anchorPoint
property to
(1.0, 1.0). Do that now by adding the following line of code directly after
playerNode
's
construction.
playerNode!.anchorPoint = CGPoint(x: 1.0, y: 1.0)
Now run the application once more. You will now see the entire
playerNode
positioned
at the top right of the scene, as shown in
Figure 2-11
.