Difference between revisions of "Legacy:Sound/pause"
From Spherical
(Created the sound.pause page) |
(navboxed) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 11: | Line 11: | ||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
var my_music = LoadSound("your_sound.ogg"); | var my_music = LoadSound("your_sound.ogg"); | ||
+ | var toggle = false; | ||
− | my_music.play( | + | my_music.play(true); |
while (!IsKeyPressed(KEY_ESCAPE)) | while (!IsKeyPressed(KEY_ESCAPE)) | ||
{ | { | ||
while (AreKeysLeft()) { | while (AreKeysLeft()) { | ||
− | if (GetKey() == KEY_ENTER) my_music.pause(); | + | if (GetKey() == KEY_ENTER) toggle ? my_music.play() : my_music.pause(); |
} | } | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | Note that the above is different from stop which will restart the sound on play. | ||
==See also== | ==See also== | ||
* Sphere [[API:Sound|Sound]] object | * Sphere [[API:Sound|Sound]] object | ||
* [[API:Sound/play|Sound.play]](repeat) | * [[API:Sound/play|Sound.play]](repeat) | ||
− | * [[API:Sound/ | + | * [[API:Sound/isPlaying|Sound.isPlaying]]() |
* [[API:Sound/stop|Sound.stop]]() | * [[API:Sound/stop|Sound.stop]]() | ||
* [[API:AreKeysLeft|AreKeysLeft]]() | * [[API:AreKeysLeft|AreKeysLeft]]() | ||
Line 34: | Line 37: | ||
* [[API:IsKeyPressed|IsKeyPressed]]() | * [[API:IsKeyPressed|IsKeyPressed]]() | ||
− | + | ||
+ | {{API:Sound/navbox}} |
Latest revision as of 22:39, 30 May 2013
Play a loaded sound.
Usage
sound.pause();
- sound Sphere Sound object. The sound to pause.
Examples
Pausing a sound with the enter key:
var my_music = LoadSound("your_sound.ogg");
var toggle = false;
my_music.play(true);
while (!IsKeyPressed(KEY_ESCAPE))
{
while (AreKeysLeft()) {
if (GetKey() == KEY_ENTER) toggle ? my_music.play() : my_music.pause();
}
}
Note that the above is different from stop which will restart the sound on play.
See also
- Sphere Sound object
- Sound.play(repeat)
- Sound.isPlaying()
- Sound.stop()
- AreKeysLeft()
- FlipScreen()
- Font.drawText()
- Font.getHeight()
- GetSystemFont()
- IsKeyPressed()