-
Notifications
You must be signed in to change notification settings - Fork 872
/
Copy pathViewController.swift
104 lines (76 loc) · 3.24 KB
/
ViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
Copyright (C) 2015 Apple Inc. All Rights Reserved.
See LICENSE.txt for this sample’s licensing information
Abstract:
Defines the iOS view controller for Adventure.
*/
import SpriteKit
class ViewController: UIViewController {
// MARK: Properties
@IBOutlet weak var coverView: UIImageView!
@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!
// MARK: View Life Cycle
override func viewDidLoad() {
// On iPhone/iPod touch we want to see a similar amount of the scene as on iPad.
// So, we set the scale of the image to be used to double the scale of the image,
// This effectively scales the cover image to 50%, matching the scene scaling.
var image = UIImage(named: "cover")!
if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
image = UIImage(CGImage: image.CGImage, scale: image.scale * 2.0, orientation: UIImageOrientation.Up)!
}
coverView.image = image
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
// Start the progress indicator animation.
loadingProgressIndicator.startAnimating()
AdventureScene.loadSceneAssetsWithCompletionHandler { loadedScene in
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 = loadedScene
self.scene.size = viewSize
self.scene.scaleMode = .AspectFill
#if DEBUG
self.skView.showsDrawCount = true
self.skView.showsFPS = true
#endif
self.scene.finishedMovingToView = {
UIView.animateWithDuration(2.0, animations: {
self.archerButton.alpha = 1.0
self.warriorButton.alpha = 1.0
self.coverView.alpha = 0.0
}, completion: { finished in
self.loadingProgressIndicator.stopAnimating()
self.loadingProgressIndicator.hidden = true
self.coverView.removeFromSuperview()
})
}
self.skView.presentScene(self.scene)
}
}
// MARK: IBActions
@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
}
}