Sound In Code: Difference between revisions
Jump to navigation
Jump to search
Sage J. Fox (talk | contribs) m (Small fix to the code (#include over include)) |
Androidtv12 (talk | contribs) No edit summary |
||
Line 2: | Line 2: | ||
Use <code>EmitSound</code> to emit a sound from a base entity: | Use <code>EmitSound</code> to emit a sound from a base entity: | ||
< | <source lang="cpp">EmitSound( "soundscript.file" );</source> | ||
See the <code>CSoundEmitterSystem</code> class in SoundEmitterSystem.cpp for overloads and implementation details. | See the <code>CSoundEmitterSystem</code> class in SoundEmitterSystem.cpp for overloads and implementation details. | ||
Line 9: | Line 9: | ||
To play a sound on the client, use the following code: | To play a sound on the client, use the following code: | ||
< | <source lang="cpp">enginesound->EmitAmbientSound( "link/to/soundfile", 1.0f );</source> | ||
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. |
Revision as of 03:29, 12 July 2018
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