add SettingsScene with background and music also boolean query for multiple audioplayer start

This commit is contained in:
127-Z3R0 2020-05-10 18:10:36 +02:00
parent 9c990cc897
commit 888d194676
4 changed files with 55 additions and 1 deletions

View File

@ -47,6 +47,7 @@
ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; };
AE151589245F18EF001D363E /* MatchmakingHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE151588245F18EF001D363E /* MatchmakingHelper.swift */; };
C04783EE2468583F004961FB /* intro-music.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = C04783ED2468583F004961FB /* intro-music.mp3 */; };
C04783F024685995004961FB /* SettingsScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04783EF24685995004961FB /* SettingsScene.swift */; };
C05FAED62468559D0006AF2E /* SoundManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C05FAED52468559D0006AF2E /* SoundManager.swift */; };
/* End PBXBuildFile section */
@ -106,6 +107,7 @@
ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = "<group>"; };
AE151588245F18EF001D363E /* MatchmakingHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatchmakingHelper.swift; sourceTree = "<group>"; };
C04783ED2468583F004961FB /* intro-music.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = "intro-music.mp3"; sourceTree = "<group>"; };
C04783EF24685995004961FB /* SettingsScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsScene.swift; sourceTree = "<group>"; };
C05FAED52468559D0006AF2E /* SoundManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SoundManager.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -166,6 +168,7 @@
110360E4244B101B008610AF /* Info.plist */,
AE151588245F18EF001D363E /* MatchmakingHelper.swift */,
3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */,
C04783EF24685995004961FB /* SettingsScene.swift */,
);
path = GoldWars;
sourceTree = "<group>";
@ -379,6 +382,7 @@
9EA3ABEB245C6DFA006BC61D /* BaseNode.swift in Sources */,
9E04AFAF245E2B73002D5CFC /* AttackActionComponent.swift in Sources */,
110360D9244B101A008610AF /* GameScene.swift in Sources */,
C04783F024685995004961FB /* SettingsScene.swift in Sources */,
116060F7245C57D2004E5A36 /* EntityManager.swift in Sources */,
3EBD242E245D9332003CECE7 /* Team.swift in Sources */,
9E174C88245DF1FF00209FF0 /* BackgroundComponent.swift in Sources */,

View File

@ -35,10 +35,13 @@ class MenuScene: SKScene {
position: CGPoint(x: midX, y: midY - 80 ),
onButtonPress: {
//TODO: create Settings Scene
self.loadScene(scene: SettingsScene(size: self.size))
}))
entityManager.add(Background(size: self.size))
soundManager.startMenuMusic()
if soundManager.isMusicPlaying == false {
soundManager.startMenuMusic()
}
}
func loadScene(scene: SKScene) {

View File

@ -0,0 +1,40 @@
//
// SettingsScene.swift
// GoldWars
//
// Created by Tim Herbst on 10.05.20.
// Copyright © 2020 SP2. All rights reserved.
//
import SpriteKit
class SettingsScene: SKScene {
var entityManager: EntityManager!
override func sceneDidLoad() {
entityManager = EntityManager(scene: self)
let positionX = self.size.width * 0.1
let positionY = self.size.height * 0.1
entityManager.add(Button(name: "backToMenuScene",
iconName: "",
text: "Back",
position: CGPoint(x: positionX, y: positionY),
onButtonPress: {
self.loadScene(scene: MenuScene(size: self.size))
}))
entityManager.add(Background(size: self.size))
}
func loadScene(scene: SKScene) {
let transition = SKTransition.flipVertical(withDuration: 0.5)
self.view?.presentScene(scene, transition: transition)
}
override func update(_ currentTime: TimeInterval) {
entityManager.getBackground()!.update(deltaTime: currentTime)
}
}

View File

@ -12,6 +12,7 @@ import AVFoundation
class SoundManager {
var audioPlayer = AVAudioPlayer()
var backgroundMainMenuAudio: URL?
var isMusicPlaying: Bool = false
func startMenuMusic() {
backgroundMainMenuAudio = Bundle.main.url(forResource: "intro-music", withExtension: "mp3")
@ -23,5 +24,11 @@ class SoundManager {
audioPlayer.numberOfLoops = -1
audioPlayer.prepareToPlay()
audioPlayer.play()
isMusicPlaying = true
}
func stopMenuMusic() {
audioPlayer.pause()
isMusicPlaying = false
}
}