Difference between revisions of "minetest.sound play"
m (Add sort key) |
(→Examples: less confusing description placement) |
||
Line 27: | Line 27: | ||
== Examples == | == Examples == | ||
+ | |||
+ | Plays the <code>testmod_testsound.ogg</code> sound at the [[position]] 0,0,0. | ||
<source> | <source> | ||
minetest.sound_play("testmod_testsound", { | minetest.sound_play("testmod_testsound", { | ||
Line 34: | Line 36: | ||
}) | }) | ||
</source> | </source> | ||
− | Plays the | + | |
+ | Plays the <code>testmod_foobar.ogg</code> sound to player "foo". | ||
<source> | <source> | ||
minetest.sound_play("testmod_foobar", { | minetest.sound_play("testmod_foobar", { | ||
Line 41: | Line 44: | ||
}) | }) | ||
</source> | </source> | ||
− | Plays | + | |
+ | Plays random <code>testmod_foobar</code> sound. | ||
<source> | <source> | ||
-- testmod/sounds listing: | -- testmod/sounds listing: | ||
Line 49: | Line 53: | ||
minetest.sound_play("testmod_foobar") | minetest.sound_play("testmod_foobar") | ||
</source> | </source> | ||
− | + | ||
[[Category:Methods|s]] | [[Category:Methods|s]] |
Revision as of 11:48, 11 May 2019
Language: | [[::minetest.sound play|English]] |
---|
Syntax
minetest.sound_play(SimpleSoundSpec, SoundParameters)
Description
Plays a sound.
Only Ogg Vorbis files are supported. For positional playing of sounds, only single-channel (mono) files are supported. Otherwise OpenAL will play them non-positionally.
SimpleSoundSpec
can be a string with the filename (without the file extention) or a table with the fields name="name"
and gain=float
.
SoundParameters
is a table with the following fields:
gain = float
: the gain. default = 1.0max_hear_distance = int
: the maximum hear distance. default = 32loop = bool
: Sound is looped. Only sounds connected to objects can be looped. default = false
The location can be specified with one of the following fields in the SoundParameters (if none is used, its played locationless to all players):
to_player = "playername"
: Sound is played locationless to the playerpos = position
: Sound is played at this positionobject = ObjectRef
: Sound is played connected to the object
The function returns a sound handle that can be passed to minetest.sound_stop(handle)
to stop the sound.
Features
You can play random sound using filename convention modname_soundname.N.ogg
(see examples)
Examples
Plays the testmod_testsound.ogg
sound at the position 0,0,0.
minetest.sound_play("testmod_testsound", {
pos = {x=0, y=0, z=0},
max_hear_distance = 100,
gain = 10.0,
})
Plays the testmod_foobar.ogg
sound to player "foo".
minetest.sound_play("testmod_foobar", {
to_player = "foo",
gain = 2.0,
})
Plays random testmod_foobar
sound.
-- testmod/sounds listing:
-- /testmod_foobar.1.ogg
-- /testmod_foobar.2.ogg
-- /testmod_foobar.3.ogg
minetest.sound_play("testmod_foobar")