void SetupSounds() { // Get an arbitrary node to attach the sounds to SCNNode node = GameView.Scene.RootNode; // The wind sound SCNAudioSource source = SCNAudioSource.FromFile("game.scnassets/sounds/wind.m4a"); source.Volume = .3f; SCNAudioPlayer player = SCNAudioPlayer.FromSource(source); source.Loops = true; source.ShouldStream = true; source.Positional = false; node.AddAudioPlayer(player); // fire source = SCNAudioSource.FromFile("game.scnassets/sounds/flamethrower.mp3"); source.Loops = true; source.Volume = 0; source.Positional = false; flameThrowerSound = SCNAudioPlayer.FromSource(source); node.AddAudioPlayer(flameThrowerSound); // hit hitSound = SCNAudioSource.FromFile("game.scnassets/sounds/ouch_firehit.mp3"); hitSound.Volume = 2f; hitSound.Load(); pshhhSound = SCNAudioSource.FromFile("game.scnassets/sounds/fire_extinction.mp3"); pshhhSound.Volume = 2f; pshhhSound.Load(); aahSound = SCNAudioSource.FromFile("game.scnassets/sounds/aah_extinction.mp3"); aahSound.Volume = 2f; aahSound.Load(); // collectable collectPearlSound = SCNAudioSource.FromFile("game.scnassets/sounds/collect1.mp3"); collectPearlSound.Volume = 0.5f; collectPearlSound.Load(); collectFlowerSound = SCNAudioSource.FromFile("game.scnassets/sounds/collect1.mp3"); collectFlowerSound.Load(); // victory victoryMusic = SCNAudioSource.FromFile("game.scnassets/sounds/Music_victory.mp3"); victoryMusic.Volume = 0.5f; }
public void AttachSampler(AudioSampler audioSampler, SCNNode node) { // Add the audio Player to the scenekit node so that it gets correct positional // adjustments node.AddAudioPlayer(audioSampler.AudioPlayer); // NOTE: AVAudioNodes that are not AVAudioPlayerNodes are not // automatically added to an AVAudioEngine by SceneKit. So we add // this audio node to the SCNNode so that it can get position updates // but we connect it manually to the AVAudioEnvironmentNode that we // get passed to us. This comes from ARSCNView in GameSceneViewController. if (this.AudioEnvironment.Engine != null) { var engine = this.AudioEnvironment.Engine; // attach the node var audioNode = audioSampler.AudioNode; engine.AttachNode(audioNode); // connect var engineFormat = engine.OutputNode.GetBusInputFormat(0); var format = new AVAudioFormat(engineFormat.SampleRate, 1); engine.Connect(audioNode, AudioEnvironment, format); // addd to the local collection this.audioSamplers.Add(audioSampler); } }
void SetupMusic() { // Get an arbitrary node to attach the sounds to. SCNNode node = GameView.Scene.RootNode; SCNAudioSource source = SCNAudioSource.FromFile("game.scnassets/sounds/music.m4a"); source.Loops = true; source.Volume = 0.25f; source.ShouldStream = true; source.Positional = false; SCNAudioPlayer player = SCNAudioPlayer.FromSource(source); node.AddAudioPlayer(player); }