Playing 3D sound
When playing sounds, for instance an explosion, it's nice that the sound of the explosion actually appears to be coming from the explosion. This can be done using 3D sound. The basic setup is very similar as using a SoundEffectInstance
, because it has support for 3D sound. We just need some extra classes: an AudioEmitter
and an AudioListener
. The emitter represents the object that will cause the sound, for instance in case of an explosion, the bomb. The emitter will have the same position as the object that creates the sound. The listener represents the object that receives the sound. In case of a game, it would be the player, and thus have the same position. Both the emitter and the listener have a property called Forward
; with the emitter, it defines the direction in which the sound should travel; with the listener, if defines the direction in which the listener is oriented. They both have properties for the position, the up vector and the velocity. The emitter also has...