CHAPTER 7 ■ ADDING SOUNDS TO YOUR XNA 3.0 PROJECT
594
protected override void Update(GameTime gameTime)
{
GamePadState gamePadState = GamePad.GetState(PlayerIndex.One);
if (gamePadState.Buttons.Back == ButtonState.Pressed)
this.Exit();
KeyboardState keyState = Keyboard.GetState();
if (keyState.IsKeyDown(Keys.Space) || (gamePadState.Buttons.B ==
➥
ButtonState.Pressed))
{
if ((cue1 == null) || (cue1.IsStopped))
{
cue1 = soundBank.GetCue("audio1");
cue1.Play();
}
}
if (keyState.IsKeyDown(Keys.Enter) || (gamePadState.Buttons.A ==
➥
ButtonState.Pressed))
if (cue1 != null)
cue1.Stop(AudioStopOptions.Immediate);
audioEngine.Update();
base.Update(gameTime);
}
The first time the spacebar is pressed, the cue1variablewillbenull.Whentheuser
pressestheEnterkey,thecueisstopped.Whentheuserpressesthespacebaragain,thecue ...