add backgroundMusic for MenuScene with SoundManager for futher Sound-Management - music with commercial use

This commit is contained in:
127-Z3R0 2020-05-10 17:44:54 +02:00
parent 3f73a6f64d
commit 9c990cc897
4 changed files with 39 additions and 0 deletions

View File

@ -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 = "<group>"; };
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>"; };
C05FAED52468559D0006AF2E /* SoundManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SoundManager.swift; sourceTree = "<group>"; };
/* 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;
};

View File

@ -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) {

View File

@ -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()
}
}

Binary file not shown.