diff --git a/GoldWars/GoldWars.xcodeproj/project.pbxproj b/GoldWars/GoldWars.xcodeproj/project.pbxproj index ebaec53..3a7facc 100644 --- a/GoldWars/GoldWars.xcodeproj/project.pbxproj +++ b/GoldWars/GoldWars.xcodeproj/project.pbxproj @@ -46,6 +46,8 @@ AB1D75A0245DEC0500671525 /* MapFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759F245DEC0500671525 /* MapFactory.swift */; }; 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 */; }; + C05FAED62468559D0006AF2E /* SoundManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C05FAED52468559D0006AF2E /* SoundManager.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -103,6 +105,8 @@ AB1D759F245DEC0500671525 /* MapFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapFactory.swift; sourceTree = ""; }; ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = ""; }; AE151588245F18EF001D363E /* MatchmakingHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatchmakingHelper.swift; sourceTree = ""; }; + C04783ED2468583F004961FB /* intro-music.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = "intro-music.mp3"; sourceTree = ""; }; + C05FAED52468559D0006AF2E /* SoundManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SoundManager.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -146,6 +150,7 @@ 110360D1244B101A008610AF /* GoldWars */ = { isa = PBXGroup; children = ( + C04783ED2468583F004961FB /* intro-music.mp3 */, 9ECD3699245C91F7008DEEBD /* GoldWars.entitlements */, 9E11FF74245CD79100EED3BE /* Partikels */, 116060F5245C5709004E5A36 /* Entities */, @@ -155,6 +160,7 @@ 9EC86BA4245C8A1E00796EF3 /* Scenes */, 9EC86BA3245C89F400796EF3 /* Storyboards */, 110360D2244B101A008610AF /* AppDelegate.swift */, + C05FAED52468559D0006AF2E /* SoundManager.swift */, 110360DA244B101A008610AF /* GameViewController.swift */, 110360DF244B101B008610AF /* Assets.xcassets */, 110360E4244B101B008610AF /* Info.plist */, @@ -347,6 +353,7 @@ 9E11FF79245CD81100EED3BE /* Fire.sks in Resources */, 110360E0244B101B008610AF /* Assets.xcassets in Resources */, 110360E3244B101B008610AF /* LaunchScreen.storyboard in Resources */, + C04783EE2468583F004961FB /* intro-music.mp3 in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -397,6 +404,7 @@ 110360D3244B101A008610AF /* AppDelegate.swift in Sources */, 9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */, 9E78ACC2245CC9EE00526FF7 /* DefBoostSkillComponent.swift in Sources */, + C05FAED62468559D0006AF2E /* SoundManager.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/GoldWars/GoldWars/Scenes/MenuScene.swift b/GoldWars/GoldWars/Scenes/MenuScene.swift index 3f8694a..946d478 100644 --- a/GoldWars/GoldWars/Scenes/MenuScene.swift +++ b/GoldWars/GoldWars/Scenes/MenuScene.swift @@ -11,8 +11,10 @@ import SpriteKit class MenuScene: SKScene { var entityManager: EntityManager! + var soundManager: SoundManager! override func sceneDidLoad() { + soundManager = SoundManager() entityManager = EntityManager(scene: self) let midX = self.size.width / 2 let midY = self.size.height / 2 @@ -35,6 +37,8 @@ class MenuScene: SKScene { //TODO: create Settings Scene })) entityManager.add(Background(size: self.size)) + + soundManager.startMenuMusic() } func loadScene(scene: SKScene) { diff --git a/GoldWars/GoldWars/SoundManager.swift b/GoldWars/GoldWars/SoundManager.swift new file mode 100644 index 0000000..f882bf0 --- /dev/null +++ b/GoldWars/GoldWars/SoundManager.swift @@ -0,0 +1,27 @@ +// +// SoundManager.swift +// GoldWars +// +// Created by Tim Herbst on 10.05.20. +// Copyright © 2020 SP2. All rights reserved. +// + +import SpriteKit +import AVFoundation + +class SoundManager { + var audioPlayer = AVAudioPlayer() + var backgroundMainMenuAudio: URL? + + func startMenuMusic() { + backgroundMainMenuAudio = Bundle.main.url(forResource: "intro-music", withExtension: "mp3") + do { + audioPlayer = try AVAudioPlayer(contentsOf: backgroundMainMenuAudio!) + } catch { + print("Datei nicht gefunden!") + } + audioPlayer.numberOfLoops = -1 + audioPlayer.prepareToPlay() + audioPlayer.play() + } +} diff --git a/GoldWars/GoldWars/intro-music.mp3 b/GoldWars/GoldWars/intro-music.mp3 new file mode 100644 index 0000000..6aaa001 Binary files /dev/null and b/GoldWars/GoldWars/intro-music.mp3 differ