Difference between revisions of "Sound In Code"

From Valve Developer Community
Jump to: navigation, search
m
(Added playing sounds via VGUI interface)
Line 12: Line 12:
  
 
You may need to include <code>#include "engine/ienginesound.h"</code> in order to get access to the interface.
 
You may need to include <code>#include "engine/ienginesound.h"</code> in order to get access to the interface.
 +
 +
== Play sounds via VGUI interface ==
 +
<source lang="cpp">
 +
include "vgui/ISurface.h"
 +
 +
using namespace vgui;
 +
 +
vgui::surface()->PlaySound( "common/talk.wav" ); // Starts from the 'sound' folder
 +
</source>
  
 
[[Category:Sound System]]
 
[[Category:Sound System]]
 
[[Category:Programming]]
 
[[Category:Programming]]

Revision as of 19:05, 8 April 2011

Emit sound from entity

Use EmitSound to emit a sound from a base entity:

EmitSound( "soundscript.file" );

See the CSoundEmitterSystem class in SoundEmitterSystem.cpp for overloads and implementation details.

Play sounds anywhere

To play a sound on the client, use the following code:

enginesound->EmitAmbientSound( "link/to/soundfile", 1.0f );

You may need to include #include "engine/ienginesound.h" in order to get access to the interface.

Play sounds via VGUI interface

include "vgui/ISurface.h"

using namespace vgui;

vgui::surface()->PlaySound( "common/talk.wav" ); // Starts from the 'sound' folder