rq.sound
since 1.4.0
Plays sounds: a game sound number, a file in the mod folder, or a sound inside a game Flash file.
They play on the game's sound effect mixer, so Config's sound volume applies, and at real time: rq.speed does not change them. A file or Flash sound is read once and kept in memory, so a sound played on every hit reads the disk once. At most 32 mod sounds play at once; one more raises an error. These play beside the game's music; rq.music puts a file in place of a music track.
-- Berserk's sound, from its Flash file
rq.sound.play_flash("Data/Flash/Battle/狂戦士発動.swf")
-- A sound of your own, looped, then faded out
local h = rq.sound.play("sfx/rain.ogg", { loop = 0, volume = 60 })
rq.sound.stop(h, 500)Functions
| Name | Summary |
|---|---|
rq.sound.play | Plays a game sound or a sound file from the mod folder. |
rq.sound.play_flash | Plays a sound kept inside a Flash file. |
rq.sound.flash_info | Lists the sounds in a Flash file: a mod's file under that key first (rq.image.add_flash), as for play_flash. |
rq.sound.stop | Stops a sound, at once or with a fade out. |
rq.sound.playing | Returns whether a sound still plays. |
rq.sound.set_volume | Changes a sound's volume, at once or over a fade. |
rq.sound.play
rq.sound.play(src, opts) -> integer|nilsince 1.4.0
Plays a game sound or a sound file from the mod folder.
A file can be WAV, OGG, FLAC, Opus or MP3, up to 64 MB. Raises an error for a missing file, a path out of the mod folder, or when 32 mod sounds already play.
local h = rq.sound.play("sfx/hit.wav", { volume = 80 })| Parameter | Type | Description |
|---|---|---|
src | integer|string | A game sound number (as for rq.scene.sound) or a path in the mod folder. |
opts (optional) | rq.SoundOpts | How to play it. |
| Returns | Type | Description |
|---|---|---|
handle | integer|nil | The handle, or nil when the number does not exist or the file is not a sound. |
See also: rq.sound.stop
rq.sound.play_flash
rq.sound.play_flash(key, opts) -> integer|nilsince 1.4.0 changed 2.63.0
Plays a sound kept inside a Flash file.
Some game sounds have no number, such as Berserk's in Data/Flash/Battle/狂戦士発動.swf. A bare key means Data/Flash/System/<key>.swf, as in rq.image.add_gif, and a file a mod added under that key (rq.image.add_flash, or a GIF) is looked at first, as the game plays it. Only uncompressed (PCM) sounds play. Raises an error when the file or that sound is missing, the sound is compressed, index is below 1, or 32 mod sounds already play.
A file's sound is read once and kept; it is read again after a mod adds, replaces or removes the file under that name.
under its name changed (a bare key and the full path are one file).
| Parameter | Type | Description |
|---|---|---|
key | string | The Flash file's key or path. |
opts (optional) | rq.SoundOpts | How to play it; index picks the sound. |
| Returns | Type | Description |
|---|---|---|
handle | integer|nil | The handle, or nil when the sound did not start. |
Changed in 2.63.0: A mod's own file from
rq.image.add_flash, and a sound read again after the file
See also: rq.sound.flash_info
rq.sound.flash_info
rq.sound.flash_info(key) -> rq.FlashSound[]|nilsince 1.4.0 changed 2.63.0
Lists the sounds in a Flash file: a mod's file under that key first (rq.image.add_flash), as for play_flash.
for i, s in ipairs(rq.sound.flash_info("Data/Flash/Battle/狂戦士発動.swf") or {}) do
rq.log(i, s.ms, s.playable)
end| Parameter | Type | Description |
|---|---|---|
key | string | The Flash file's key or path, as for play_flash. |
| Returns | Type | Description |
|---|---|---|
sounds | rq.FlashSound []|nil | The sounds, in the order index counts them; nil when there is no such file. |
Changed in 2.63.0: A mod's own file from
rq.image.add_flash.
rq.sound.stop
rq.sound.stop(handle, fade_ms) -> booleansince 1.4.0
Stops a sound, at once or with a fade out.
| Parameter | Type | Description |
|---|---|---|
handle | integer | A handle from play or play_flash. |
fade_ms (optional) | integer | The fade out, in milliseconds. Default 0: stop at once. |
| Returns | Type | Description |
|---|---|---|
stopped | boolean | false when the handle already ended. |
rq.sound.playing
rq.sound.playing(handle) -> booleansince 1.4.0
Returns whether a sound still plays.
An ended handle stays false, even when its slot plays something new.
| Parameter | Type | Description |
|---|---|---|
handle | integer | A handle from play or play_flash. |
| Returns | Type | Description |
|---|---|---|
playing | boolean | true while it plays. |
rq.sound.set_volume
rq.sound.set_volume(handle, volume, fade_ms) -> booleansince 1.4.0
Changes a sound's volume, at once or over a fade.
| Parameter | Type | Description |
|---|---|---|
handle | integer | A handle from play or play_flash. |
volume | integer | The new volume, 0 to 100, clamped. |
fade_ms (optional) | integer | The fade, in milliseconds. Default 0: at once. |
| Returns | Type | Description |
|---|---|---|
changed | boolean | false when the handle already ended. |
