-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettings Scene
147 lines (89 loc) · 4.5 KB
/
Settings Scene
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
//
// SettingsScene.swift
// Physics Breaker
//
// Created by Charlie Bushman on 1/7/16.
// Copyright © 2016 imaginary inc. All rights reserved.
//
import Foundation
import UIKit
import SpriteKit
class SettingsScene: SKScene{
let titleLabel = SKLabelNode()
let musicVolumeLabel = SKLabelNode()
let soundVolumeLabel = SKLabelNode()
let musicVolumeSlider = UISlider()
let soundVolumeSlider = UISlider()
let menuButton = UIButton()
override func didMoveToView(view: SKView) {
self.backgroundColor = UIColor.whiteColor() //sets scene's background to white
setUpScene()
setUpZAxis()
}
override func willMoveFromView(view:SKView){
self.removeAllChildren()
}
func setUpScene(){
//Sets a Data Manager for the scene
let dataManager = DataManagement()
/*LABEL: Displays the title 'SETTINGS'*/
titleLabel.fontColor = UIColor.blackColor()
titleLabel.fontSize = 60
titleLabel.position = CGPoint(x: CGRectGetMidX(self.frame), y: 550)
titleLabel.text = "SETTINGS"
self.addChild(titleLabel)
/*LABEL: Displays the title for the music volume slider*/
musicVolumeLabel.fontColor = UIColor.blackColor()
musicVolumeLabel.fontSize = 40
musicVolumeLabel.position = CGPoint(x: 200, y: 425)
musicVolumeLabel.text = "Music Volume: "
self.addChild(musicVolumeLabel)
/*LABEL: Displays the title for the sound volume slider*/
soundVolumeLabel.fontColor = UIColor.blackColor()
soundVolumeLabel.fontSize = 40
soundVolumeLabel.position = CGPoint(x: 200, y: 285)
soundVolumeLabel.text = "Sounds Volume: "
self.addChild(soundVolumeLabel)
/*SLIDER: Slider that sets the music volume*/
musicVolumeSlider.maximumValue = 100.0
musicVolumeSlider.value = dataManager.getMusicVolume()
musicVolumeSlider.frame = CGRect(x: self.view!.frame.size.width-350, y: self.view!.frame.size.height-225, width: 300, height: 50)
musicVolumeSlider.addTarget(self, action: #selector(changeMusicVolume), forControlEvents: UIControlEvents.ValueChanged)
musicVolumeSlider.addTarget(self, action: #selector(changeMusicVolume), forControlEvents: UIControlEvents.TouchUpInside)
self.view!.addSubview(musicVolumeSlider)
/*SLIDER: Slider that sets the sound volume*/
soundVolumeSlider.maximumValue = 100.0
soundVolumeSlider.value = dataManager.getSoundVolume()
soundVolumeSlider.frame = CGRect(x: self.view!.frame.size.width-350, y: self.view!.frame.size.height-150, width: 300, height: 50)
soundVolumeSlider.addTarget(self, action: #selector(changeSoundVolume), forControlEvents: UIControlEvents.ValueChanged)
soundVolumeSlider.addTarget(self, action: #selector(changeSoundVolume), forControlEvents: UIControlEvents.TouchUpInside)
self.view!.addSubview(soundVolumeSlider)
/*BUTTON: Allows user to return to the main menu*/
menuButton.setTitle("MENU", forState: UIControlState.Normal)
menuButton.titleLabel!.font = UIFont(name: "HelveticaNeue-UltraLight", size: 20.0)
menuButton.frame = CGRect(x: self.view!.frame.size.width-100, y: self.view!.frame.size.height-300, width: 100, height: 30)
menuButton.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
menuButton.addTarget(self, action: #selector(goToMenuSettings), forControlEvents: UIControlEvents.TouchUpInside)
self.view!.addSubview(menuButton)
}
func setUpZAxis(){
titleLabel.zPosition = 1.0
musicVolumeLabel.zPosition = 1.0
soundVolumeLabel.zPosition = 1.0
}
func goToMenuSettings(sender: UIButton){
let menuScene = MenuScene(size: self.size)
self.view?.presentScene(menuScene, transition: SKTransition.crossFadeWithDuration(0.0))
menuButton.removeFromSuperview()
musicVolumeSlider.removeFromSuperview()
soundVolumeSlider.removeFromSuperview()
}
func changeMusicVolume(sender: UISlider){
let dataManager = DataManagement()
dataManager.setMusicVolume(musicVolumeSlider.value)
}
func changeSoundVolume(sender: UISlider){
let dataManager = DataManagement()
dataManager.setSoundVolume(soundVolumeSlider.value)
}
}