Difference between revisions of "Legacy:Sound/play"

From Spherical
Jump to: navigation, search
(filled)
(Usage: Stylized usage)
Line 2: Line 2:
  
 
==Usage==
 
==Usage==
''sound''.'''play'''(''repeat'');
+
{{Usage|object=sound|func=play|params=repeat}}
  
 
* '''sound''' Sphere [[API:Sound|Sound]] object. The sound to play.
 
* '''sound''' Sphere [[API:Sound|Sound]] object. The sound to play.

Revision as of 19:02, 20 May 2013

Play a loaded sound.

Usage

sound.play(repeat);


  • sound Sphere Sound object. The sound to play.
  • repeat Boolean. If true, the sound will loop.

Examples

How to load and play a simple sound:

var my_music = LoadSound("calm_blue_ocean.ogg");
my_music.play(true);

How to play a quick, simple sound for something like a menu blip:

var menu_blip = LoadSound("blip.ogg");
var font = GetSystemFont();

while (!IsKeyPressed(KEY_ESCAPE))
{
  while (AreKeysLeft())
  {
    if (GetKey() == KEY_SPACE)
    {
      if (menu_blip.isPlaying())
        menu_blip.stop();
      menu_blip.play(false);
    }
  }
  
  font.drawText(0, 0, "Press Space to hear the menu blips.");
  font.drawText(0, font.getHeight(), "Press ESC to quit.");
  FlipScreen();
}

The above example works by stopping the previous menu blip from playing, and then replaying it.

See also