Game Development Reference
In-Depth Information
The next thing to check out is the viewDidLoad() method. This is where you really
start to see your first active Sprite Kit code. The first thing you do, after calling su-
per.viewDidLoad() , is to configure your main view. In the first step, you downcast
your standard UIView to an SKView . The SKView is the view that will host your game
scene mentioned earlier. For the most part, the SKView acts much like any UIView , with
the exception that it has a collection of game-related properties and utility methods like
the line following the downcast.
skView.showsFPS = true
This property of the SKView is used to show or hide the frames per second the applica-
tion is rendering—the higher, the better.
After configuring the main view, you create and configure the GameScene .
scene = GameScene(size: skView.bounds.size)
scene.scaleMode = .AspectFill
The first line creates a new instance of the GameScene initializing the size to match the
size of the view that will host the scene. After that, you set scaleMode to
AspectFill . The scaleMode (implemented by the enum SKSceneScaleMode ) is
used to determine how the scene will be scaled to match the view that will contain it.
Table 1-1 describes each of the available scaleMode properties.
Table 1-1 . The SKSceneScaleModes
SKSceneScaleMode
Definition
The Fill scaleMode will fill the entire SKView without
consideration to the ratio of width to height.
SKSceneScaleMode.Fill
The AspectFill mode will scale the scene to fill the host-
ing SKView while maintaining the aspect ratio of the scene,
but there may be some cropping if the hosting SKView 's as-
pect ratio is different. This is the mode you are using in this
game.
SKSceneScaleMode.AspectFill
The AspectFit mode will scale the scene to fill the hosting
SKView while maintaining the aspect ratio of the scene, but
there may be some letterboxing if the hosting SKView 's as-
pect ratio is different.
SKSceneScaleMode.AspectFit
Search WWH ::




Custom Search