diff --git a/GoldWars/GoldWars/Components/BackgroundComponent.swift b/GoldWars/GoldWars/Components/BackgroundComponent.swift index ce5c16a..f74d5dd 100644 --- a/GoldWars/GoldWars/Components/BackgroundComponent.swift +++ b/GoldWars/GoldWars/Components/BackgroundComponent.swift @@ -12,7 +12,7 @@ class BackgroundComponent: GKComponent{ var nodes = [SKSpriteNode]() let size: CGSize - static var isMovingBackgroundEnabled: Bool = true + static var isMovingBackgroundEnabled = true init(size: CGSize) { self.size = size @@ -28,7 +28,7 @@ class BackgroundComponent: GKComponent{ } func update(){ - if BackgroundComponent.isMovingBackgroundEnabled == true { + if BackgroundComponent.isMovingBackgroundEnabled { for node in nodes{ node.position.x -= 2 if node.position.x < -(size.width) { diff --git a/GoldWars/GoldWars/Scenes/MenuScene.swift b/GoldWars/GoldWars/Scenes/MenuScene.swift index 248dce7..bca03d2 100644 --- a/GoldWars/GoldWars/Scenes/MenuScene.swift +++ b/GoldWars/GoldWars/Scenes/MenuScene.swift @@ -23,7 +23,7 @@ class MenuScene: SKScene { onButtonPress: { if CommandLine.arguments.contains("--no-matchmaking") { self.loadScene(scene: GameScene(size: self.size)) - SoundManager.stopMenuMusic() + SoundManager.sharedInstance.stopMenuMusic() } else { MatchmakingHelper.sharedInstance.presentMatchmaker(scene: self) } @@ -37,8 +37,8 @@ class MenuScene: SKScene { })) entityManager.add(Background(size: self.size)) - if SoundManager.isMusicPlaying == false && SoundManager.isMusicEnabled == true { - SoundManager.startMenuMusic() + if SoundManager.sharedInstance.isMusicPlaying == false && SoundManager.sharedInstance.isMusicEnabled == true { + SoundManager.sharedInstance.startMenuMusic() } } diff --git a/GoldWars/GoldWars/SettingsScene.swift b/GoldWars/GoldWars/SettingsScene.swift index e106848..9453979 100644 --- a/GoldWars/GoldWars/SettingsScene.swift +++ b/GoldWars/GoldWars/SettingsScene.swift @@ -28,29 +28,25 @@ class SettingsScene: SKScene { text: "ON/OFF", position: CGPoint(x: self.size.width / 2, y: self.size.height / 2), onButtonPress: { - if SoundManager.isMusicPlaying == true { - SoundManager.stopMenuMusic() - SoundManager.isMusicEnabled = false + if SoundManager.sharedInstance.isMusicPlaying { + SoundManager.sharedInstance.stopMenuMusic() + SoundManager.sharedInstance.isMusicEnabled = false } else { - SoundManager.isMusicEnabled = true - SoundManager.startMenuMusic() + SoundManager.sharedInstance.isMusicEnabled = true + SoundManager.sharedInstance.startMenuMusic() } - })) entityManager.add(Button(name: "StopMovingBackground", iconName: "", text: "MOVE/STOP", position: CGPoint(x: self.size.width / 2, y: self.size.height / 2 - 100), onButtonPress: { - if BackgroundComponent.isMovingBackgroundEnabled == true { + if BackgroundComponent.isMovingBackgroundEnabled { BackgroundComponent.isMovingBackgroundEnabled = false } else { BackgroundComponent.isMovingBackgroundEnabled = true } - - })) - entityManager.add(Background(size: self.size)) } diff --git a/GoldWars/GoldWars/SoundManager.swift b/GoldWars/GoldWars/SoundManager.swift index 9d5dd94..4f8f34d 100644 --- a/GoldWars/GoldWars/SoundManager.swift +++ b/GoldWars/GoldWars/SoundManager.swift @@ -10,13 +10,15 @@ import SpriteKit import AVFoundation class SoundManager { - static var audioPlayer = AVAudioPlayer() - static var backgroundMainMenuAudio: URL? - static var isMusicPlaying: Bool = false - static var isMusicEnabled: Bool = true + public static var sharedInstance = SoundManager() - static func startMenuMusic() { - SoundManager.isMusicPlaying = true + var audioPlayer = AVAudioPlayer() + var backgroundMainMenuAudio: URL? + var isMusicPlaying = false + var isMusicEnabled = true + + func startMenuMusic() { + self.isMusicPlaying = true backgroundMainMenuAudio = Bundle.main.url(forResource: "intro-music", withExtension: "mp3") do { audioPlayer = try AVAudioPlayer(contentsOf: backgroundMainMenuAudio!) @@ -25,21 +27,21 @@ class SoundManager { } audioPlayer.numberOfLoops = -1 audioPlayer.prepareToPlay() - if SoundManager.isMusicEnabled == true { + if self.isMusicEnabled == true { audioPlayer.play() } } - static func stopMenuMusic() { + func stopMenuMusic() { audioPlayer.pause() - SoundManager.isMusicPlaying = false + self.isMusicPlaying = false } - static func setVolume(_ volume: Float) { + func setVolume(_ volume: Float) { audioPlayer.volume = volume } - static func getVolume() -> Float { + func getVolume() -> Float { return audioPlayer.volume } }