public void Play() { var category = _soundBank.AudioEngine.Categories[_categoryID]; var curInstances = category.GetPlayingInstanceCount(); if (curInstances >= category.maxInstances) { var prevSound = category.GetOldestInstance(); if (prevSound != null) { prevSound.SetFade(0.0f, category.fadeOut); prevSound.Stop(AudioStopOptions.Immediate); SetFade(category.fadeIn, 0.0f); } } if (_complexSound) { foreach (XactClip clip in _soundClips) { clip.Play(); } } else { if (_wave != null && _wave.State != SoundState.Stopped && _wave.IsLooped) { _wave.Stop(); } else { _wave = _soundBank.GetSoundEffectInstance(_waveBankIndex, _trackIndex); } if (_wave == null) { // We couldn't create a sound effect instance, most likely // because we've reached the sound pool limits. return; } _wave.Play(); } }
public void Play() { if (complexSound) { foreach (XactClip clip in soundClips) { clip.Play(); } } else { if (wave.State == SoundState.Playing) { wave.Stop(); } wave.Play(); } }
public override void Play() { if (_wav != null) { if (_wav.State != SoundState.Stopped) { _wav.Stop(); } if (_streaming) { _wav.Dispose(); } else { _wav._isXAct = false; } _wav = null; } Play(true); }
/// <summary> /// Iterates the list of playing instances, stop them and return them to the pool if they are instances of the given SoundEffect. /// </summary> /// <param name="effect">The SoundEffect</param> internal static void StopPooledInstances(SoundEffect effect) { SoundEffectInstance inst = null; for (var x = 0; x < _playingInstances.Count;) { inst = _playingInstances[x]; if (inst._effect == effect) { inst.Stop(true); // stop immediatly Add(inst); continue; } x++; } }
/// <summary> /// Iterates the list of playing instances, returning them to the pool if they /// have stopped playing. /// </summary> internal static void Update() { SoundEffectInstance inst = null; // Cleanup instances which have finished playing. for (var x = 0; x < _playingInstances.Count;) { inst = _playingInstances[x]; if (inst.IsDisposed || inst.State == SoundState.Stopped || (inst._effect == null && !inst._isDynamic)) { #if OPENAL inst.Stop(true); // force stopping it to free its AL source #endif Add(inst); continue; } x++; } }
public void DestroySoundEffect(SoundEffect soundEffect) { OpenALSoundController.AllocationsLock.EnterUpgradeableReadLock(); OpenALSoundController.BufferAllocation bufferAllocation; if (!this.allocatedBuffers.TryGetValue(soundEffect, out bufferAllocation)) { OpenALSoundController.AllocationsLock.ExitUpgradeableReadLock(); } else { bool flag = false; OpenALSoundController.ActiveLock.EnterUpgradeableReadLock(); for (int index = this.activeSoundEffects.Count - 1; index >= 0; --index) { SoundEffectInstance soundEffectInstance = this.activeSoundEffects[index]; if (soundEffectInstance.SoundEffect == soundEffect) { OpenALSoundController.ActiveLock.EnterWriteLock(); if (!soundEffectInstance.IsDisposed) { flag = true; soundEffectInstance.Stop(false); soundEffectInstance.Dispose(); } this.activeSoundEffects.RemoveAt(index); OpenALSoundController.ActiveLock.ExitWriteLock(); } } OpenALSoundController.ActiveLock.ExitUpgradeableReadLock(); if (flag) { Trace.WriteLine("[OpenAL] Delete active sources & buffer for " + soundEffect.Name); } OpenALSoundController.AllocationsLock.EnterWriteLock(); this.allocatedBuffers.Remove(soundEffect); OpenALSoundController.AllocationsLock.ExitWriteLock(); this.freeBuffers.Push(bufferAllocation.BufferId); OpenALSoundController.AllocationsLock.ExitUpgradeableReadLock(); } }
public void LoadAudio( SoundEffect selectPiece, SoundEffect unMove, SoundEffect aMove, SoundEffect convert) { this.selectPiece = selectPiece; this.unMove = unMove; this.aMove = aMove; this.convert = convert; seiConvert = convert.Play(1.0f, 0.0f, 0.0f, false); seiConvert.Stop(); seiAvaMove = aMove.Play(1.0f, 0.0f, 0.0f, false); seiAvaMove.Stop(); }
/// <summary> /// /// </summary> /// <param name="se"></param> public void StopSoundEffect(SoundEffectInstance se) { se.Stop(); this.ActiveSoundEffects.Remove(se); }
/// <summary> /// Stop a looped soundeffect. /// </summary> /// <param name="instance">The sound you want to stop.</param> private void StopSoundEffect(SoundEffectInstance instance) { if (instance.IsLooped) { instance.Stop(); instance.IsLooped = false; } }
public static void StopSfx(SoundEffectInstance soundCue) { soundCue.Stop(true); soundCue.Dispose(); }
public void play3dSound(SoundEffectInstance sound, Vector3 soundPos) { AudioListener listener = new AudioListener(); listener.Position = game.ship.pos; AudioEmitter emitter = new AudioEmitter(); emitter.Position = soundPos; //sound.Apply3D(listener, emitter); throws An unhandled exception of type 'System.AccessViolationException' occurred in SharpDX.XAudio2.dll sound.Stop(); sound.Play(); }
public void PoolSound(SoundEffectInstance sound, string soundName) { sound.Stop(); effectsPool[soundName].Enqueue(sound); }
public void RemoveSound(SoundEffectInstance se) { se.Stop(); loopedSounds.Remove(se); }
void CollectDrug() { DrugsCount++; switch (DrugsCount) { case 1: // change props foreach (var tileset in map.Tilesets) { if (tileset.Name == "propsit") { tileset.Texture = PropsTileSheetDark; } } break; case 2: // change enemies instance.Stop(true); instance = Musa2.CreateInstance(); instance.IsLooped = true; instance.Volume = volume; instance.Play(); break; case 3: // change player instance.Stop(true); instance = Musa3.CreateInstance(); instance.IsLooped = true; instance.Volume = volume; instance.Play(); player.ChangeTexture(PlayerTextureDark); break; case 4: // change maptextures instance.Stop(true); instance = Musa4.CreateInstance(); instance.IsLooped = true; instance.Volume = volume; instance.Play(); foreach (var enemy in enemies) { if (enemy.Type == Enemy.EnemyType.Nurse) { enemy.ChangeTexture(NurseTextureDark); } else { enemy.ChangeTexture(DoctorTextureDark); } } foreach (var tileset in map.Tilesets) { if (tileset.Name == "tilesetti3") { tileset.Texture = WorldTileSheetDark; } } break; case 5: // win game Reset(); Data.GameState = State.End; break; default: foreach (var tileset in map.Tilesets) { if (tileset.Name == "propsit") { tileset.Texture = PropsTileSheet; } } foreach (var enemy in enemies) { if (enemy.Type == Enemy.EnemyType.Nurse) { enemy.ChangeTexture(NurseTexture); } else { enemy.ChangeTexture(DoctorTexture); } } player.ChangeTexture(PlayerTexture); foreach (var tileset in map.Tilesets) { if (tileset.Name == "tilesetti3") { tileset.Texture = WorldTileSheet; } } break; } }
public static void StopEffect(SoundEffectInstance soundEffectInstance) { if (soundEffectInstance != null) { soundEffectInstance.Stop(); soundEffects.Remove(soundEffectInstance); } }
//method for mouse on main menu public Rectangle MouseClicked(int x, int y, Game1 game, ref int currentLevel, ref List<Enemy> enemies, ref List<PickUpItem> Items, ref List<Projectile> projectiles, ref int timer, ContentManager Content, ref Character player, ref string wepUnl, ref bool songPlaying, ref SoundEffectInstance song) { Rectangle mouseClickRect = new Rectangle(x, y, 1, 1); Rectangle startbuttonRect = new Rectangle((int)startButtonPosition.X, (int)startButtonPosition.Y, 300, 108); Rectangle exitbuttonRect = new Rectangle((int)exitButtonPosition.X, (int)exitButtonPosition.Y, 600, 192); if (gameState == "StartMenu") { //player clicks start if (mouseClickRect.Intersects(startbuttonRect)) { try { gameState = "Case"; CheckGameState(); } catch (GameStateNotFoundException) { gameState = "Case"; } } //player exits game else if (mouseClickRect.Intersects(exitbuttonRect)) { game.Exit(); } // player clicked on options else if (mouseClickRect.Intersects(optionsButtonPosition)) { try { gameState = "OptionsMenu"; lastState = "StartMenu"; CheckGameState(); } catch (GameStateNotFoundException e) { Console.WriteLine(e.ToString()); gameState = ""; } } else if (mouseClickRect.Intersects(levelSelectButtonPosition)) { try { gameState = "LevelSelect"; lastState = "StartMenu"; CheckGameState(); } catch (GameStateNotFoundException e) { Console.WriteLine(e.ToString()); gameState = ""; } } } //level select menu else if (gameState == "LevelSelect") { // back button clicked if (mouseClickRect.Intersects(backButtonPosition)) { try { gameState = lastState; CheckGameState(); } catch (GameStateNotFoundException e) { Console.WriteLine(e.ToString()); gameState = ""; lastState = ""; } } else if (mouseClickRect.Intersects(levelRect[0]) || mouseClickRect.Intersects(levelRect[1]) || mouseClickRect.Intersects(levelRect[2]) || mouseClickRect.Intersects(levelRect[3]) || mouseClickRect.Intersects(levelRect[4]) || mouseClickRect.Intersects(levelRect[5]) || mouseClickRect.Intersects(levelRect[6]) || mouseClickRect.Intersects(levelRect[7])) { Shooting.CreateWeapons(Content); if (mouseClickRect.Intersects(levelRect[0]) && levelClears[0] != 0) { currentLevel = 1; SkillSystem.CreateSkills(Content, player); player.Health = player.MaxHealth; player.Stamina = 100; wepUnl = ""; player.Weapon = Shooting.weapons[1]; player.FrameLevel = 1; enemies.Clear(); Items.Clear(); projectiles.Clear(); timer = 0; gameState = "LevelSwitch"; CheckGameState(); } else if (mouseClickRect.Intersects(levelRect[1]) && levelClears[1] != 0) { currentLevel = 2; Shooting.weapons[2].IsAcquired = true; SkillSystem.CreateSkills(Content, player); player.Health = player.MaxHealth; player.Stamina = 100; wepUnl = ""; player.Weapon = Shooting.weapons[1]; player.FrameLevel = 1; enemies.Clear(); Items.Clear(); projectiles.Clear(); timer = 0; gameState = "LevelSwitch"; CheckGameState(); } else if (mouseClickRect.Intersects(levelRect[2]) && levelClears[2] != 0) { currentLevel = 3; Shooting.weapons[2].IsAcquired = true; SkillSystem.CreateSkills(Content, player); player.Health = player.MaxHealth; player.Stamina = 100; wepUnl = ""; player.Weapon = Shooting.weapons[1]; player.FrameLevel = 1; enemies.Clear(); Items.Clear(); projectiles.Clear(); timer = 0; gameState = "LevelSwitch"; CheckGameState(); } else if (mouseClickRect.Intersects(levelRect[3]) && levelClears[3] != 0) { currentLevel = 4; Shooting.weapons[2].IsAcquired = true; Shooting.weapons[3].IsAcquired = true; SkillSystem.CreateSkills(Content, player); player.Health = player.MaxHealth; player.Stamina = 100; wepUnl = ""; player.Weapon = Shooting.weapons[1]; player.FrameLevel = 1; enemies.Clear(); Items.Clear(); projectiles.Clear(); timer = 0; gameState = "LevelSwitch"; CheckGameState(); } else if (mouseClickRect.Intersects(levelRect[4]) && levelClears[4] != 0) { currentLevel = 5; Shooting.weapons[2].IsAcquired = true; Shooting.weapons[3].IsAcquired = true; SkillSystem.CreateSkills(Content, player); player.Health = player.MaxHealth; player.Stamina = 100; wepUnl = ""; player.Weapon = Shooting.weapons[1]; player.FrameLevel = 1; enemies.Clear(); Items.Clear(); projectiles.Clear(); timer = 0; gameState = "LevelSwitch"; CheckGameState(); } else if (mouseClickRect.Intersects(levelRect[5]) && levelClears[5] != 0) { currentLevel = 6; Shooting.weapons[2].IsAcquired = true; Shooting.weapons[3].IsAcquired = true; Shooting.weapons[4].IsAcquired = true; SkillSystem.CreateSkills(Content, player); player.Health = player.MaxHealth; player.Stamina = 100; wepUnl = ""; player.Weapon = Shooting.weapons[1]; player.FrameLevel = 1; enemies.Clear(); Items.Clear(); projectiles.Clear(); timer = 0; gameState = "LevelSwitch"; CheckGameState(); } else if (mouseClickRect.Intersects(levelRect[6]) && levelClears[6] != 0) { currentLevel = 7; Shooting.weapons[2].IsAcquired = true; Shooting.weapons[3].IsAcquired = true; Shooting.weapons[4].IsAcquired = true; SkillSystem.CreateSkills(Content, player); player.Health = player.MaxHealth; player.Stamina = 100; wepUnl = ""; player.Weapon = Shooting.weapons[1]; player.FrameLevel = 1; enemies.Clear(); Items.Clear(); projectiles.Clear(); timer = 0; gameState = "LevelSwitch"; CheckGameState(); } else if (mouseClickRect.Intersects(levelRect[7]) && levelClears[7] != 0) { currentLevel = 8; Shooting.weapons[2].IsAcquired = true; Shooting.weapons[3].IsAcquired = true; Shooting.weapons[4].IsAcquired = true; SkillSystem.CreateSkills(Content, player); player.Health = player.MaxHealth; player.Stamina = 100; wepUnl = ""; player.Weapon = Shooting.weapons[1]; player.FrameLevel = 1; enemies.Clear(); Items.Clear(); projectiles.Clear(); timer = 0; gameState = "LevelSwitch"; CheckGameState(); } } } //Death screen else if (gameState == "Death") { if (mouseClickRect.Intersects(exitbuttonRect)) { gameState = "StartMenu"; CheckGameState(); } }//Victory state for beating the game else if (gameState == "Victory") { if (mouseClickRect.Intersects(rightStartButton)) { gameState = "StartMenu"; CheckGameState(); } }//Page for the Case story else if (gameState == "Case") { if (mouseClickRect.Intersects(rightStartButton)) { SkillSystem.CreateSkills(Content, player); Shooting.CreateWeapons(Content); player.Health = player.MaxHealth; player.Stamina = 100; wepUnl = ""; player.Weapon = Shooting.weapons[1]; player.FrameLevel = 1; currentLevel = 1; enemies.Clear(); Items.Clear(); projectiles.Clear(); timer = 0; gameState = "LevelSwitch"; CheckGameState(); } } //puased screen else if (gameState == "Paused") { if (mouseClickRect.Intersects(exitbuttonRect)) { saveLevelClears(); song.Stop(); songPlaying = false; gameState = "StartMenu"; CheckGameState(); } else if (mouseClickRect.Intersects(optionsButtonPosition)) { try { gameState = "OptionsMenu"; lastState = "Paused"; CheckGameState(); } catch (GameStateNotFoundException e) { Console.WriteLine(e.ToString()); gameState = ""; } } else if (mouseClickRect.Intersects(resumeButtonPosition)) { try { song.Resume(); gameState = "Playing"; CheckGameState(); } catch (GameStateNotFoundException e) { Console.WriteLine(e.ToString()); gameState = ""; } } } //options screen method else if (gameState == "OptionsMenu") { // back button clicked if (mouseClickRect.Intersects(backButtonPosition)) { try { gameState = lastState; CheckGameState(); } catch (GameStateNotFoundException e) { Console.WriteLine(e.ToString()); gameState = ""; lastState = ""; } } // sounds button clicked else if (mouseClickRect.Intersects(soundsButtonPosition)) { try { gameState = "SoundsMenu"; } catch (GameStateNotFoundException e) { Console.WriteLine(e.ToString()); gameState = ""; } } // graphics button clicked else if (mouseClickRect.Intersects(graphicsButtonPosition)) { try { gameState = "GraphicsMenu"; } catch (GameStateNotFoundException e) { Console.WriteLine(e.ToString()); gameState = ""; } } // controls button clicked else if (mouseClickRect.Intersects(controlButtonPosition)) { try { gameState = "Controls"; } catch (GameStateNotFoundException e) { Console.WriteLine(e.ToString()); gameState = ""; } } } // Sounds menu else if (gameState == "SoundsMenu") { if (mouseClickRect.Intersects(backButtonPosition)) { try { gameState = "OptionsMenu"; } catch (GameStateNotFoundException e) { Console.WriteLine(e.ToString()); gameState = ""; } } } // Controls menu else if (gameState == "Controls") { if (mouseClickRect.Intersects(controlBackButtonPosition)) { try { gameState = "OptionsMenu"; } catch (GameStateNotFoundException e) { Console.WriteLine(e.ToString()); gameState = ""; } } } // graphics menu else if (gameState == "GraphicsMenu") { if (mouseClickRect.Intersects(backButtonPosition)) { try { gameState = "OptionsMenu"; } catch (GameStateNotFoundException e) { Console.WriteLine(e.ToString()); gameState = ""; } } } return mouseClickRect; }
/* */ void StopSoundMem(SoundEffectInstance paramSoundEffect) { try { paramSoundEffect.Stop(); } catch (Exception localException) { /* */ } }
public override void Load() { camera = new Camera (Engine.ScreenWidth, Engine.ScreenHeight); effectManager = new EffectManager (this); cats = new List<NyanCat>(); projectiles = new List<Projectile>(); batch = Engine.Batch; catTexture = Engine.ContentManager.Load<Texture2D> ("NyanCat"); deathTexture = Engine.ContentManager.Load<Texture2D> ("Death"); healthBarTexture = Engine.ContentManager.Load<Texture2D> ("HealthBar"); reloadBarTexture = Engine.ContentManager.Load<Texture2D> ("ReloadBar"); nyanSoundEffect = Engine.ContentManager.Load<SoundEffect> ("Sound/Nyan"); nyanInstance = nyanSoundEffect.CreateInstance(); nyanInstance.IsLooped = false; nyanInstance.Volume = 0.5f; nyanInstance.Stop(); deathFont = Engine.ContentManager.Load<SpriteFont> ("DeathFont"); deathLocation = new Vector2 (HealthBarWidth + 20, 5); EditorLoad(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // Create a music track soundtrack = Content.Load<SoundEffect>("Behind-every-Idea"); music = soundtrack.CreateInstance(); playergun = Content.Load<SoundEffect>("starting_pistol"); zombiehit = Content.Load<SoundEffect>("Zombie Attacked"); playerhit = Content.Load<SoundEffect>("Bite"); //Make the track looped and if its stop then play it music.IsLooped = true; music.Volume = 0.75f; if (music.State == SoundState.Playing) music.Stop(); // TODO: use this.Content to load your game content here mainfont = Content.Load<SpriteFont>("quartz4"); // Load the quartz4 font background = new graphic2d(Content, "ZombieBG", displaywidth, displayheight); background2 = new graphic2d(Content, "skyline", displaywidth, displayheight); backgroundGO = new graphic2d(Content, "gameoverbg", displaywidth, displayheight); up = new sprite2d(Content, "up", 115, displayheight - 150, 0.25f, Color.White, true); down = new sprite2d(Content, "down",115, displayheight - 50, 0.25f, Color.White, true); left = new sprite2d(Content, "left", 55, displayheight - 100, 0.25f, Color.White, true); right = new sprite2d(Content, "right", 175, displayheight - 100, 0.25f, Color.White, true); controlshowto = new sprite2d(Content, "Controls", 425, displayheight - 225, 0.65f, Color.White, true); firebut = new sprite2d(Content, "fire", 700, displayheight - 100, 0.50f, Color.White, true); menuback = new sprite2d(Content, "right", displaywidth - 50, 50, 0.25f, Color.White, true); menuoptions[0] = new sprite2d(Content, "buttonstart", displaywidth / 2, 150, 0.50f, Color.White, true); menuoptions[1] = new sprite2d(Content, "buttonhowtoplay", displaywidth / 2, 220, 0.50f, Color.White, true); menuoptions[2] = new sprite2d(Content, "buttonhighscore", displaywidth / 2, 290, 0.50f, Color.White, true); menuoptions[3] = new sprite2d(Content, "buttonexit", displaywidth / 2, 360, 0.50f, Color.White, true); // Initialise robot1 object playerchar = new model3d(Content, "player", 2f, new Vector3(0, 0, 0), new Vector3(0, 0, 0), 0.002f, 0.06f, 10); playerchar.bboxsize = new Vector3(25, 115, 25); // Load High Scores in using (IsolatedStorageFile savegamestorage = IsolatedStorageFile.GetUserStoreForApplication()) { if (savegamestorage.FileExists("highscores.txt")) { using (IsolatedStorageFileStream fs = savegamestorage.OpenFile("highscores.txt", System.IO.FileMode.Open)) { using (StreamReader sr = new StreamReader(fs)) { string line; for (int i = 0; i < numberofhighscores; i++) { line = sr.ReadLine(); highscores[i] = Convert.ToInt32(line); } sr.Close(); } } } } // Sort high scores Array.Sort(highscores); Array.Reverse(highscores); }
public static void StopMusic(SoundEffectInstance instance) { if(instance != null) { instance.Stop(); instance.Dispose(); } }
public void SetBacgroundMusic(ContentManager content, string source, float volume) { if (Constants.Music && !string.IsNullOrEmpty(source)) { if (backgroundMusic != null) backgroundMusic.Stop(); toVolume = volume; backgroundMusic = getSound(content, source); backgroundMusic.Stop(); //backgroundMusic.IsLooped = true; backgroundMusic.Volume = 0f; backgroundMusic.Play(); } }
public void StopLoopingSound(SoundEffectInstance sfxInst) { if (sfxInst != null && sfxInst.State == SoundState.Playing) { sfxInst.Stop(); } }
protected void Salon() { count1 =0; yeux = false; vintro = false; ouvrir = false; cavev = false; cuisinev1 = false; cuisinev2 = false; chambrev1 = false; chambrev2 = false; chambrev3 = false; chambrev4 = false; soundEffectInstance.Stop (); finaction = false; inputdebut = ""; issalon = true; ischambre = false; iscuisine = false; iscave = false; iscaveaction = false; ischambreaction = false; iscuisineaction = false; isecrandebut = false; iscave = false; isecrandebut = false; isecrandemarrage = false; isfin = false; compteurenigme= 0; totalcuisine = 0; totalcave = 0; compteurA = 0; compteurZ = 0; // Fond de l'écran background = Content.Load<Texture2D> ("Salon"); // Texture de la fille girl.LoadContent ("Girl"); soundEffectInstance.Stop (); soundeffect = Content.Load<SoundEffect> ("Sounds/Salon"); soundEffectInstance = soundeffect.CreateInstance (); soundEffectInstance.IsLooped = true; soundEffectInstance.Play (); if (cuisinevalid && lettref) { soundEffectInstance.Stop (); soundeffect = Content.Load<SoundEffect> ("Sounds/F"); soundEffectInstance = soundeffect.CreateInstance (); soundEffectInstance.Play (); lettref = false; } if (chambrevalid && lettrei) { soundEffectInstance.Stop (); soundeffect = Content.Load<SoundEffect> ("Sounds/I"); soundEffectInstance = soundeffect.CreateInstance (); soundEffectInstance.Play (); lettrei = false; } if (cavevalid && lettreo) { soundEffectInstance.Stop (); soundeffect = Content.Load<SoundEffect> ("Sounds/O"); soundEffectInstance = soundeffect.CreateInstance (); soundEffectInstance.Play (); lettreo = false; } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { GraphicsDevice device = GraphicsDevice; _hudInfo1Font = Content.Load<SpriteFont>("HUDInfo1"); _spriteBatch = new SpriteBatch(device); _screenshotTarget = new RenderTarget2D(device, _screenWidth, _screenHeight, 1, device.DisplayMode.Format); _screenshotTargetLeft = new RenderTarget2D(device, _screenWidth, _screenHeight, 1, device.DisplayMode.Format); _screenshotTargetRight = new RenderTarget2D(device, _screenWidth, _screenHeight, 1, device.DisplayMode.Format); if (_settings.RenderMode == RenderModes.StereoCrossConverged) { _leftEyeRender = new RenderTarget2D(device, _screenWidth, _screenHeight, 1, device.DisplayMode.Format); _rightEyeRender = new RenderTarget2D(device, _screenWidth, _screenHeight, 1, device.DisplayMode.Format); } if (!String.IsNullOrEmpty(_scenario.BackgroundMusic)) { try { _music = Content.Load<SoundEffect>(_scenario.BackgroundMusic); _musicInst = _music.CreateInstance(); _musicInst.Volume = 1.0f; _musicInst.IsLooped = true; _musicInst.Stop(true); _musicInst.Play(); } catch (Exception e) { Console.WriteLine(@"Could not load background music sound effect file. " + e); } } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // load texture and contents messageFont = this.Content.Load<SpriteFont>(MessageFontContentName); scoreFont = this.Content.Load<SpriteFont>(ScoreFontContentName); laserTexture = this.Content.Load<Texture2D>(LaserContentName); spaceshipTexture = this.Content.Load<Texture2D>(SpaceshipContentName); enemy4Texture = this.Content.Load<Texture2D>(Enemy4ContentName); explosionTexture = this.Content.Load<Texture2D>(ExplosionsContentName); backgroundTexture = this.Content.Load<Texture2D>(BackgroundContentName); starTexture = this.Content.Load<Texture2D>(ParallaxStarContentName); //bgmEffect = this.Content.Load<SoundEffect>(BgmContentName); bgmEffect = this.Content.Load<SoundEffect>(this.settings.BgmSoundEffect); explosionSoundEffect = this.Content.Load<SoundEffect>(ExplosionSoundContentName); explosionSound = explosionSoundEffect.CreateInstance(); explosionSound.Volume = 1.0F; laserSoundEffect = this.Content.Load<SoundEffect>(LaserSoundContentName); laserSound = laserSoundEffect.CreateInstance(); laserSound.Volume = 1.0F; // create sprites spaceshipSprite = new SpaceshipSprite(spaceshipTexture); backgroundSprite = new BackgroundSprite(backgroundTexture, graphics); // create sprite generators enemyGenerator = new SpriteGenerator<EnemySprite>( () => new EnemySprite(enemy4Texture, new Vector2(Utils.GetRandomNumber(1, GraphicsDevice.Viewport.Width - enemy4Texture.Width), 1), Utils.GetRandomNumber(5, 10)), enemyPool, TimeSpan.FromMilliseconds(1000.0F/settings.NumOfEnemiesPerSecond)); starGenerator = new SpriteGenerator<ParallaxStarSprite>(() => new ParallaxStarSprite(starTexture, new Vector2( Utils.GetRandomNumber(1, GraphicsDevice.Viewport.Width - starTexture.Width), 1), Utils.GetRandomNumber(5, 20)), starPool, TimeSpan.FromMilliseconds(100)); gameOverScene = new GameOverScene(this, () => !spaceshipSprite.IsActive, () => { this.enemyPool.Clear(); this.laserPool.Clear(); this.explosionPool.Clear(); this.enemyGenerator.IsActive = false; if (explosionSound != null && !explosionSound.IsDisposed) { explosionSound.Stop(true); explosionSound.Dispose(); } if (laserSound != null && !laserSound.IsDisposed) { laserSound.Stop(true); laserSound.Dispose(); } bgmEffect.Dispose(); }) {IsActive = !settings.LiveForever}; var bgm = bgmEffect.CreateInstance(); bgm.IsLooped = true; bgm.Play(); }