Game Development Reference
In-Depth Information
SKSceneScaleMode
Definition
The
ResizeFill
mode will modify the size of the scene to
fit the hosting view exactly.
SKSceneScaleMode.ResizeFill
Note
When setting the
scaleMode
property of the scene, you are using a
shortened syntax to represent the mode you are setting, specifically, the
.AspectFill
mode. You can use this dot syntax because you know the type
of the
scaleMode
property is an
SKSceneScaleMode
, which is an enum
containing all of the scale modes.
Once you have the view and the scene configured, there is only one last thing to
do—present the scene. This is done with the last line in
viewDidLoad()
.
skView.presentScene(scene)
The GameScene Class
Now that I have walked you through each line of the
GameViewController
class, it
is time to talk about the
GameScene
class. Again, for convenience's sake, I am including
the source for the
GameScene.swift
file a second time:
import SpriteKit
class GameScene: SKScene {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(size: CGSize) {
super.init(size: size)
backgroundColor = SKColor(red: 0.0, green: 0.0,
blue: 0.0, alpha: 1.0)
}
}
As you look over
GameScene
, you will notice there is really not much to it. It extends
SKScene
and implements two
init()
methods; the first
init()
that takes an
NSCoder
can be ignored. You had to add this only because a Swift class does not inherit