1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
Music
=====
The Music object lets you play music. This is meant to handle background music; therefore, only one music can be played at a time.
Unlike regular [sounds](/engine/sound), musics are streamed, (i.e., not loaded completely in memory). Given the longer nature of musics, this improves memory usage and helps with the loading times.
*Example*
```
using SurgeEngine.Level;
// Fades the music in a linear fashion ;)
object "MyMusicFader"
{
public music = Level.music;
prevVolume = music.volume;
fadeTime = 1.0; // given in seconds
state "main"
{
}
state "fadeout"
{
music.volume -= Time.delta / fadeTime;
if(music.volume <= 0.0) {
music.pause();
music.volume = prevVolume;
state = "main";
}
}
// call fadeOut() to make the
// music fade smoothly
fun fadeOut(seconds)
{
if(state == "main")
prevVolume = music.volume;
fadeTime = seconds;
state = "fadeout";
}
}
```
Factory
-------
#### Music
`Audio.Music(path)`
Creates a Music object associated with a certain file.
*Arguments*
* `path`: string. The path of the music - usually a file in the *musics/* folder.
*Returns*
A Music object.
*Example*
```
using SurgeEngine.Audio.Music;
object "MusicTest"
{
music = Music("musics/options.ogg");
state "main"
{
// loop music
if(!music.playing)
music.play();
}
}
```
Properties
----------
#### playing
`playing`: boolean, read-only.
Will be `true` if the music is playing.
#### volume
`volume`: number.
The volume of the music, a value between 0.0 and 1.0, inclusive (zero means silence).
Functions
---------
#### play
`play()`
Plays the music (once). To make it loop, play it whenever `music.playing` is `false`.
#### stop
`stop()`
Stops the music. Once the music is stopped, it can only be played again from the beginning.
#### pause
`pause()`
Pauses the music. A paused music can be resumed later with `play()`.
|