Game Development Reference
In-Depth Information
println("The size is (\(size.width), \(size.height)).")
Now run the application again using the iPhone 4s simulator. After you do, look in the
console window. You will see the following output:
The size is (320.0, 480.0).
This is the size of the scene running on an iPhone 4s. You can try this again running on
either of the iPhone 5 or 6 simulator. These values tell you the size of your scene (the
viewport into your game world).
If you want to position
SKNode
objects into the visible world of your game, you have to
set their positions inside the range of (0, 0) to (320, 480) on the iPhone 4s or from (0, 0) to
(320, 568) on the iPhone 5s. Take a moment and play around with the coordinate system.
Go back to the
GameScene.init()
method and change the position of the
player-
Node
using the following line:
playerNode!.position = CGPoint(x: size.width / 2, y:
size.height / 2)
With this change, you are positioning the
playerNode
in the center of the scene. To see
the position change, run the app in the simulator again. You will now see your player in
the middle of your scene, as shown in
Figure 2-7
.