fix multiple calls from startMenuMusic with static Bool, stop music when enter Game
This commit is contained in:
parent
888d194676
commit
c143179df8
@ -25,6 +25,7 @@ class MenuScene: SKScene {
|
|||||||
onButtonPress: {
|
onButtonPress: {
|
||||||
if CommandLine.arguments.contains("--no-matchmaking") {
|
if CommandLine.arguments.contains("--no-matchmaking") {
|
||||||
self.loadScene(scene: GameScene(size: self.size))
|
self.loadScene(scene: GameScene(size: self.size))
|
||||||
|
self.soundManager.stopMenuMusic()
|
||||||
} else {
|
} else {
|
||||||
MatchmakingHelper.sharedInstance.presentMatchmaker(scene: self)
|
MatchmakingHelper.sharedInstance.presentMatchmaker(scene: self)
|
||||||
}
|
}
|
||||||
@ -34,12 +35,11 @@ class MenuScene: SKScene {
|
|||||||
text: "Settings",
|
text: "Settings",
|
||||||
position: CGPoint(x: midX, y: midY - 80 ),
|
position: CGPoint(x: midX, y: midY - 80 ),
|
||||||
onButtonPress: {
|
onButtonPress: {
|
||||||
//TODO: create Settings Scene
|
|
||||||
self.loadScene(scene: SettingsScene(size: self.size))
|
self.loadScene(scene: SettingsScene(size: self.size))
|
||||||
}))
|
}))
|
||||||
entityManager.add(Background(size: self.size))
|
entityManager.add(Background(size: self.size))
|
||||||
|
|
||||||
if soundManager.isMusicPlaying == false {
|
if SoundManager.isMusicPlaying == false {
|
||||||
soundManager.startMenuMusic()
|
soundManager.startMenuMusic()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
import SpriteKit
|
import SpriteKit
|
||||||
|
|
||||||
class SettingsScene: SKScene {
|
class SettingsScene: SKScene {
|
||||||
|
|
||||||
var entityManager: EntityManager!
|
var entityManager: EntityManager!
|
||||||
|
|
||||||
override func sceneDidLoad() {
|
override func sceneDidLoad() {
|
||||||
|
@ -12,9 +12,10 @@ import AVFoundation
|
|||||||
class SoundManager {
|
class SoundManager {
|
||||||
var audioPlayer = AVAudioPlayer()
|
var audioPlayer = AVAudioPlayer()
|
||||||
var backgroundMainMenuAudio: URL?
|
var backgroundMainMenuAudio: URL?
|
||||||
var isMusicPlaying: Bool = false
|
static var isMusicPlaying: Bool = false
|
||||||
|
|
||||||
func startMenuMusic() {
|
func startMenuMusic() {
|
||||||
|
SoundManager.isMusicPlaying = true
|
||||||
backgroundMainMenuAudio = Bundle.main.url(forResource: "intro-music", withExtension: "mp3")
|
backgroundMainMenuAudio = Bundle.main.url(forResource: "intro-music", withExtension: "mp3")
|
||||||
do {
|
do {
|
||||||
audioPlayer = try AVAudioPlayer(contentsOf: backgroundMainMenuAudio!)
|
audioPlayer = try AVAudioPlayer(contentsOf: backgroundMainMenuAudio!)
|
||||||
@ -24,11 +25,10 @@ class SoundManager {
|
|||||||
audioPlayer.numberOfLoops = -1
|
audioPlayer.numberOfLoops = -1
|
||||||
audioPlayer.prepareToPlay()
|
audioPlayer.prepareToPlay()
|
||||||
audioPlayer.play()
|
audioPlayer.play()
|
||||||
isMusicPlaying = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func stopMenuMusic() {
|
func stopMenuMusic() {
|
||||||
audioPlayer.pause()
|
audioPlayer.pause()
|
||||||
isMusicPlaying = false
|
SoundManager.isMusicPlaying = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user