Learn-iOS-Swift-by-Examples/Adventure/Adventure iOS/ViewController.swift

78 lines
2.2 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
Copyright (C) 2014 Apple Inc. All Rights Reserved.
See LICENSE.txt for this samples licensing information
Abstract:
Defines the iOS view controller for Adventure
*/
import SpriteKit
class ViewController: UIViewController {
@IBOutlet weak var skView: SKView!
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var gameLogo: UIImageView!
@IBOutlet weak var loadingProgressIndicator: UIActivityIndicatorView!
@IBOutlet weak var archerButton: UIButton!
@IBOutlet weak var warriorButton: UIButton!
var scene: AdventureScene!
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
// Start the progress indicator animation.
loadingProgressIndicator.startAnimating()
AdventureScene.loadSceneAssetsWithCompletionHandler {
var viewSize = self.view.bounds.size
// On iPhone/iPod touch we want to see a similar amount of the scene as on iPad.
// So, we set the size of the scene to be double the size of the view, which is
// the whole screen, 3.5- or 4- inch. This effectively scales the scene to 50%.
if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
viewSize.height *= 2
viewSize.width *= 2
}
self.scene = AdventureScene(size: viewSize)
self.scene.scaleMode = .AspectFill
self.loadingProgressIndicator.stopAnimating()
self.loadingProgressIndicator.hidden = true
self.skView.showsDrawCount = true
self.skView.showsFPS = true
self.skView.presentScene(self.scene)
UIView.animateWithDuration(2.0) {
self.archerButton.alpha = 1.0
self.warriorButton.alpha = 1.0
}
}
}
@IBAction func chooseArcher(_: AnyObject) {
scene.startLevel(.Archer)
gameLogo.hidden = true
warriorButton.hidden = true
archerButton.hidden = true
}
@IBAction func chooseWarrior(_: AnyObject) {
scene.startLevel(.Warrior)
gameLogo.hidden = true
warriorButton.hidden = true
archerButton.hidden = true
}
}