Gute Tag liebe XNA Freunde
Hiermit Release ich für euch das Audio Input für eure Spiele.
Es ist schon alles perfekt eingestellt. Ihr müsst es nur noch an eurem
XNA Game anpassen.
Hiermit Release ich für euch das Audio Input für eure Spiele.
Es ist schon alles perfekt eingestellt. Ihr müsst es nur noch an eurem
XNA Game anpassen.
Brainfuck-Quellcode
- /*//---------------------------------------------------//
- * Audio.cs *
- * Microsoft XNA Game Platform *
- * Adventure of Kanaarh *
- * Copyright (C) Jok3r *
- * Copyright (C) Kevin Kaymak. All rights reserved *
- */
- //--------------------------------------------------//
- using System;
- using System.Collections.Generic;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- namespace AdventureofK
- {
- public class Audio : GameComponent
- {
- private static Audio audio = null;
- private AudioEngine audioEngine;
- private SoundBank soundBank;
- private WaveBank waveBank;
- private Audio(Game game, string settingsFile, string waveBankFile, string soundBankFile)
- : base(game)
- {
- try
- {
- audioEngine = new AudioEngine(settingsFile);
- waveBank = new WaveBank(audioEngine, waveBankFile);
- soundBank = new SoundBank(audioEngine, soundBankFile);
- }
- catch (NoAudioHardwareException)
- {
- audioEngine = null;
- waveBank = null;
- soundBank = null;
- }
- }
- public static void Initialize(Game game, string settingsFile, string waveBankFile, string soundBankFile)
- {
- audio = new Audio(game, settingsFile, waveBankFile, soundBankFile);
- if (game != null)
- {
- game.Components.Add(audio);
- }
- }
- public static Cue GetCue(string cueName)
- {
- if (String.IsNullOrEmpty(cueName) ||
- (audio == null) || (audio.audioEngine == null) ||
- (audio.soundBank == null) || (audio.waveBank == null))
- {
- return null;
- }
- return audio.soundBank.GetCue(cueName);
- }
- public static void PlayCue(string cueName)
- {
- if ((audio != null) && (audio.audioEngine != null) &&
- (audio.soundBank != null) && (audio.waveBank != null))
- {
- audio.soundBank.PlayCue(cueName);
- }
- }
- private Cue musicCue;
- private Stack<string> musicCueNameStack = new Stack<string>();
- public static void PlayMusic(string cueName)
- {
- if (audio != null)
- {
- audio.musicCueNameStack.Clear();
- PushMusic(cueName);
- }
- }
- public static void PushMusic(string cueName)
- {
- if ((audio != null) && (audio.audioEngine != null) &&
- (audio.soundBank != null) && (audio.waveBank != null))
- {
- audio.musicCueNameStack.Push(cueName);
- if ((audio.musicCue == null) ||
- (audio.musicCue.Name != cueName))
- {
- if (audio.musicCue != null)
- {
- audio.musicCue.Stop(AudioStopOptions.AsAuthored);
- audio.musicCue.Dispose();
- audio.musicCue = null;
- }
- audio.musicCue = GetCue(cueName);
- if (audio.musicCue != null) ;
- {
- audio.musicCue.Play();
- }
- }
- }
- }
- public static void PopMusic()
- {
- if ((audio != null) && (audio.audioEngine != null) &&
- (audio.soundBank != null) && (audio.waveBank != null))
- {
- string cueName = null;
- if (audio.musicCueNameStack.Count > 0)
- {
- audio.musicCueNameStack.Pop();
- if (audio.musicCueNameStack.Count > 0)
- {
- cueName = audio.musicCueNameStack.Peek();
- }
- }
- if ((audio.musicCue == null) ||
- (audio.musicCue.Name != cueName))
- {
- if (audio.musicCue != null)
- {
- audio.musicCue.Stop(AudioStopOptions.AsAuthored);
- audio.musicCue.Dispose();
- audio.musicCue = null;
- }
- if (!String.IsNullOrEmpty(cueName))
- {
- audio.musicCue = GetCue(cueName);
- if (audio.musicCue != null)
- {
- audio.musicCue.Play();
- }
- }
- }
- }
- }
- public static void StopMusic()
- {
- if (audio != null)
- {
- audio.musicCueNameStack.Clear();
- if (audio.musicCue != null)
- {
- audio.musicCue.Stop(AudioStopOptions.AsAuthored);
- audio.musicCue.Dispose();
- audio.musicCue = null;
- }
- }
- }
- public override void Update(GameTime gameTime)
- {
- if (audioEngine != null)
- {
- audioEngine.Update();
- }
- base.Update(gameTime);
- }
- protected override void Dispose(bool disposing)
- {
- try
- {
- if (disposing)
- {
- StopMusic();
- if (soundBank != null)
- {
- soundBank.Dispose();
- soundBank = null;
- }
- if (waveBank != null)
- {
- waveBank.Dispose();
- waveBank = null;
- }
- if (audioEngine != null)
- {
- audioEngine.Dispose();
- audioEngine = null;
- }
- }
- }
- finally
- {
- base.Dispose(disposing);
- }
- }
- }
- }
Ihr müsst nur euren Namespace anpassen.
Auserdem müsst ihr in eurer Game.cs folgende dinge adden.
im Feld
und schon könnt ihr euren Sound und eure Musik
im Spiel / XNA verwenden.
Für diesen Code habe ich ca 3 Stunden harte Arbeit gebraucht.
Es sind:
-185 Zeilen
-k.A Absätze
-6.411 Zeichen
- 394 Wörter
Ich werde schauen das ich noch mehr solche Dateien Releasen werde, da ich
ja weniger Zeit habe ein paar XNA Tutorials zu schreiben.
Wer Support brauch bei diesem Code, kann sich gerne an mich wenden.
Auserdem müsst ihr in eurer Game.cs folgende dinge adden.
im Feld
im Spiel / XNA verwenden.
Für diesen Code habe ich ca 3 Stunden harte Arbeit gebraucht.
Es sind:
-185 Zeilen
-k.A Absätze
-6.411 Zeichen
- 394 Wörter
Ich werde schauen das ich noch mehr solche Dateien Releasen werde, da ich
ja weniger Zeit habe ein paar XNA Tutorials zu schreiben.
Wer Support brauch bei diesem Code, kann sich gerne an mich wenden.