Game Development Reference
In-Depth Information
The second problem is the anchoring of the nodes. Unlike UIViews, which are placed
on screen using their top-left corner coordinates, SKNodes are getting placed on the
screen based on their anchorPoint property. The following figure explains what
anchor points are. By default, the anchor point is set at (0.5, 0.5), which means that
the sprite position is its center point. This comes in handy when you need to rotate
the sprite, as this way it rotates around its center axis.
0,1
1,1
0.5,0.5
0,0
1,0
Anchor point positions
Imagine that the square in the preceding figure is your sprite. Different anchor
points mean that you use these points as the position of the sprite. The anchor point
at (0, 0) means that the left-bottom corner of our sprite will be on the position of the
sprite itself. If it is at (0.5, 0.5), the center of the sprite will be on the position point.
Anchor points go from 0 to 1 and represent the size of the sprite. So, if you make
your anchor point (0.5, 0.5), it will be exactly on sprite center.
We might want to use the (0,0) anchor point for our text label.
The problem is that we can't set an anchor point for SKLabelNode .
There are several ways to overcome this problem, such as adding an empty
SKSpriteNode , attaching SKLabelNode to it, and setting the anchor
point of the first node to (0,0). We will leave this as an exercise for you.
Adding a background image to our game
First we need to add the background file to our project. Xcode 5 offers new ways to
handle your assets. Find background.png in resource files for this chapter. Find
images.xcassets in the project navigator on the left-hand side of the screen. Click on
it and you will see a list of resources currently in your application. Drag-and-drop
background.png into the left-hand list near Appicon and LaunchImage . Background
will be added to the list of available resources. Select it and drag it from the 1x box to
the 2x box, as this is a high-resolution image to use on retina devices.
 
Search WWH ::




Custom Search