Game Development Reference
In-Depth Information
class GameViewController: UIViewController {
var scene: GameScene!
override func prefersStatusBarHidden() -> Bool {
return true
}
override func viewDidLoad() {
super.viewDidLoad()
// 1. Configure the main view
let skView = view as SKView
skView.showsFPS = true
// 2. Create and configure our game scene
scene = GameScene(size: skView.bounds.size)
scene.scaleMode = .AspectFill
// 3. Show the scene.
skView.presentScene(scene)
}
}
Starting with the first line of this controller, you see a simple import including the Sprite
Kit framework. This line makes all the Sprite Kit related classes available to your
GameViewController . After that, you have a standard class definition—the
GameViewController extends a UIViewController .
After the class definition, you see the declaration of the optional variable scene, which is
declared as the type GameScene. GameScene is the class that will be doing most of
your work. It is where you will be adding the game logic. You will look at this class in the
next section.
Notice one thing about the scene variable. It is an optional. You know it is an optional
because an exclamation point ( ! ) follows its declaration. You declared this variable as an
optional because you are not going to initialize it until the viewDidLoad() method
fires and Swift requires you to initialize all properties in a class either at their declaration
or in the init() . If you don't initialize a property in either of these locations, then you
must declare the property as optional. You will see the use of optionals throughout all of
the examples in this topic.
After the scene declaration, you see an override of the UIViewController 's
viewDidLoad() method. Here you return true because you don't want a status bar
displayed in the game.
Search WWH ::




Custom Search