Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- //add to fields in game1
- SoundManager soundManager;
- //Add to Game1 Constructer
- soundManager = new SoundManager(this);
- Components.Add(soundManager);
- */
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.GamerServices;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- namespace RPGGame
- {
- /// <summary>
- /// This is a game component that implements IUpdateable.
- /// </summary>
- public class SoundManager : Microsoft.Xna.Framework.GameComponent
- {
- private AudioEngine engine;
- private WaveBank waveBank;
- private SoundBank soundBank;
- private Cue cue;
- public SoundManager(Game game)
- : base(game)
- {
- engine = new AudioEngine(@"Content/Audio/GameAudio.xgs");
- waveBank = new WaveBank(engine, @"Content/Audio/Wave Bank.xwb");
- soundBank = new SoundBank(engine, @"Content/Audio/Sound Bank.xsb");
- }
- /// <summary>
- /// Allows the game component to perform any initialization it needs to before starting
- /// to run. This is where it can query for any required services and load content.
- /// </summary>
- public override void Initialize()
- {
- // TODO: Add your initialization code here
- cue = soundBank.GetCue("Inception");
- base.Initialize();
- }
- /// <summary>
- /// Allows the game component to update itself.
- /// </summary>
- /// <param name="gameTime">Provides a snapshot of timing values.</param>
- public override void Update(GameTime gameTime)
- {
- engine.Update();
- switch (GameState.Instance.State)
- {
- case GameStateType.Meny:
- if (!cue.Name.Equals("Inception"))
- cue.Stop(AudioStopOptions.Immediate);
- if (!cue.IsPlaying)
- {
- cue = soundBank.GetCue("Inception");
- cue.Play();
- }
- break;
- case GameStateType.inGame:
- if (!cue.Name.Equals("PartyRockAnthem"))
- cue.Stop(AudioStopOptions.Immediate);
- if (!cue.IsPlaying)
- {
- cue = soundBank.GetCue("PartyRockAnthem");
- cue.Play();
- }
- break;
- case GameStateType.credits:
- if (!cue.Name.Equals("Morrowind"))
- cue.Stop(AudioStopOptions.Immediate);
- if (!cue.IsPlaying)
- {
- cue = soundBank.GetCue("Morrowind");
- cue.Play();
- }
- break;
- }
- base.Update(gameTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment