Legacy:Sound/play

From Spherical
Jump to: navigation, search

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


API:Sound/navbox