-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStartScene.swift
145 lines (107 loc) · 4.16 KB
/
StartScene.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//
// StartScene.swift
// Jump!
//
// Created by Kyle Minshall on 12/11/14.
// Copyright (c) 2014 tmg. All rights reserved.
//
import SpriteKit
import GameKit
class StartScene: SKScene, GKGameCenterControllerDelegate {
class func scene(size:CGSize) -> StartScene {
return StartScene(size: size)
}
var gameCenter: String = ""
override init(size: CGSize) {
super.init(size: size)
backgroundColor = SKColor.whiteColor()
let over = SKLabelNode(fontNamed: "Helvetica-Bold")
over.fontColor = SKColor.blackColor()
over.fontSize = 52
over.text = "Jump!"
over.position = CGPointMake(frame.size.width/2, frame.size.height*2/3)
addChild(over)
let play = playButton()
play.position = CGPointMake(frame.size.width/2, frame.size.height/2)
play.zPosition = 1
play.name = "play"
let text = SKLabelNode(fontNamed: "Helvetica")
text.fontSize = 34
text.fontColor = SKColor.whiteColor()
text.position = CGPointMake(frame.size.width/2, frame.size.height/2)
text.zPosition = 2
text.text = "Play"
text.name = "play"
addChild(play)
addChild(text)
let score = scoreButton()
score.position = CGPointMake(frame.size.width/2, frame.size.height/2 - 75)
score.zPosition = 1
score.name = "score"
let text2 = SKLabelNode(fontNamed: "Helvetica")
text2.fontSize = 34
text2.fontColor = SKColor.whiteColor()
text2.position = score.position
text2.zPosition = 2
text2.text = "Scores"
text2.name = "score"
addChild(score)
addChild(text2)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func didMoveToView(view: SKView) {
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
let node = nodeAtPoint(location)
if node.name == "play" {
let nextLevel = SelectScene(size: frame.size)
view!.presentScene(nextLevel, transition:SKTransition.fadeWithDuration(0.5))
}
if node.name == "score" {
showScores()
}
}
}
override func update(currentTime: NSTimeInterval) {
}
func showScores() {
var vc = self.view?.window?.rootViewController
var gcViewController: GKGameCenterViewController = GKGameCenterViewController()
gcViewController.gameCenterDelegate = self
gcViewController.viewState = GKGameCenterViewControllerState.Leaderboards
gcViewController.leaderboardIdentifier = gameCenter
vc?.presentViewController(gcViewController, animated: true, completion: nil)
}
func gameCenterViewControllerDidFinish(gameCenterViewController: GKGameCenterViewController!)
{
gameCenterViewController.dismissViewControllerAnimated(true, completion: nil)
}
class playButton: SKNode {
override init() {
super.init()
let button = SKShapeNode(path: CGPathCreateWithRect(CGRectMake(-100, -15, 200, 50), nil))
button.fillColor = SKColor(red:0.144, green:0.8, blue:0.381, alpha:1)
button.name = "play"
addChild(button)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
class scoreButton: SKNode {
override init() {
super.init()
let button = SKShapeNode(path: CGPathCreateWithRect(CGRectMake(-100, -15, 200, 50), nil))
button.fillColor = SKColor(red:0.31, green:0.74, blue:0.95, alpha:1)
button.name = "score"
addChild(button)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
}