Difference between revisions of "Play"

From King Arthur's Gold Wiki
Jump to: navigation, search
(Created page with "<onlyinclude> Plays the a sound file at the given position (position used to determine if it can be heard). </onlyinclude> The first argument is the path to the sound file to pl...")
 
 
(One intermediate revision by the same user not shown)
Line 5: Line 5:
 
The first argument is the path to the sound file to play.
 
The first argument is the path to the sound file to play.
 
The second is a [[Vec2f]] representing the position the sound's source is meant to be at.
 
The second is a [[Vec2f]] representing the position the sound's source is meant to be at.
 +
 +
This method is part of the Sound namespace so you need to prefix calls to it with 'Sound::'.
  
 
There are two variants, one of which will also accepts a volume and pitch as floats.
 
There are two variants, one of which will also accepts a volume and pitch as floats.
 
<syntaxhighlight lang="cpp">
 
<syntaxhighlight lang="cpp">
void Play(const string &soundFileName, Vec2f position)
+
void Sound::Play(const string &soundFileName, Vec2f position)
void Play(const string &soundFileName, Vec2f position, f32 volume, f32 pitch)
+
void Sound::Play(const string &soundFileName, Vec2f position, f32 volume, f32 pitch)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 18: Line 20:
  
 
Example from Entities/Vehicles/Scripts/BoatLogic.as:
 
Example from Entities/Vehicles/Scripts/BoatLogic.as:
<syntaxhighlight lang="cpp">
+
<syntaxhighlight lang="cpp" highlight="5">
 
case Boat::turnaround:
 
case Boat::turnaround:
 
{
 
{

Latest revision as of 22:20, 6 September 2012

Plays the a sound file at the given position (position used to determine if it can be heard).


The first argument is the path to the sound file to play. The second is a Vec2f representing the position the sound's source is meant to be at.

This method is part of the Sound namespace so you need to prefix calls to it with 'Sound::'.

There are two variants, one of which will also accepts a volume and pitch as floats.

void Sound::Play(const string &soundFileName, Vec2f position)
void Sound::Play(const string &soundFileName, Vec2f position, f32 volume, f32 pitch)

Example from Entities/Characters/Scripts/KnightLogic.as:

Sound::Play( "Sounds/thud.ogg", this.getPosition() );

Example from Entities/Vehicles/Scripts/BoatLogic.as:

case Boat::turnaround:
{
  this.SetFacingLeft( !this.isFacingLeft() );
  if (this.isInWater())
    Sound::Play( "Sounds/SplashSlow.ogg", this.getPosition(), 1.0f, 0.7f );}