Difference between revisions of "Legacy:Sound/play"
From Spherical
(created) |
(filled) |
||
Line 2: | Line 2: | ||
==Usage== | ==Usage== | ||
+ | ''sound''.'''play'''(''repeat''); | ||
+ | |||
+ | * '''sound''' Sphere [[API:Sound|Sound]] object. The sound to play. | ||
+ | * '''repeat''' Boolean. If true, the sound will loop. | ||
==Examples== | ==Examples== | ||
+ | How to load and play a simple sound: | ||
+ | |||
+ | <syntaxhighlight lang="javascript"> | ||
+ | var my_music = LoadSound("calm_blue_ocean.ogg"); | ||
+ | my_music.play(true); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | How to play a quick, simple sound for something like a menu blip: | ||
+ | |||
+ | <syntaxhighlight lang="javascript"> | ||
+ | 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(); | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | The above example works by stopping the previous menu blip from playing, and then replaying it. | ||
==See also== | ==See also== | ||
+ | * Sphere [[API:Sound|Sound]] object | ||
+ | * [[API:Sound/isPlaying|Sound.isPlaying]]() | ||
+ | * [[API:Sound/pause|Sound.pause]]() | ||
+ | * [[API:Sound/stop|Sound.stop]]() | ||
+ | * [[API:AreKeysLeft|AreKeysLeft]]() | ||
+ | * [[API:FlipScreen|FlipScreen]]() | ||
+ | * [[API:Font/drawText|Font.drawText]]() | ||
+ | * [[API:Font/getHeight|Font.getHeight]]() | ||
+ | * [[API:GetSystemFont|GetSystemFont]]() | ||
+ | * [[API:IsKeyPressed|IsKeyPressed]]() | ||
+ | |||
+ | [[Category:Functions]] |
Revision as of 18:44, 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
- Sphere Sound object
- Sound.isPlaying()
- Sound.pause()
- Sound.stop()
- AreKeysLeft()
- FlipScreen()
- Font.drawText()
- Font.getHeight()
- GetSystemFont()
- IsKeyPressed()