Difference between revisions of "minetest.sound play"
Jump to navigation
Jump to search
Line 11: | Line 11: | ||
<code>SoundParameters</code> is a table with the following fields: | <code>SoundParameters</code> is a table with the following fields: | ||
− | * <code>gain = float</code>: the gain | + | * <code>gain = float</code>: the gain. default = 1.0 |
− | * <code>max_hear_distance = int</code>: the maximum hear distance | + | * <code>max_hear_distance = int</code>: the maximum hear distance. default = 32 |
− | * <code>loop = bool</code>: Sound is looped | + | * <code>loop = bool</code>: Sound is looped. Only sounds connected to objects can be looped. default = false |
− | The location can be specified with one of the following fields (if none is used, its played locationless to all players): | + | |
+ | The location can be specified with one of the following fields in the SoundParameters (if none is used, its played locationless to all players): | ||
* <code>to_player = "playername"</code>: Sound is played locationless to the player | * <code>to_player = "playername"</code>: Sound is played locationless to the player | ||
* <code>pos = [[position]]</code>: Sound is played at this position | * <code>pos = [[position]]</code>: Sound is played at this position | ||
Line 21: | Line 22: | ||
The function returns a sound hanlder that can be passed to <source enclose=none>minetest.sound_stop(handle)</source> to stop the sound. | The function returns a sound hanlder that can be passed to <source enclose=none>minetest.sound_stop(handle)</source> to stop the sound. | ||
− | {{ | + | == Examples == |
+ | <source> | ||
+ | minetest.sound_play("testmod_testsound", { | ||
+ | pos = {x=0, y=0, z=0}, | ||
+ | max_hear_distance = 100, | ||
+ | gain = 10.0, | ||
+ | }) | ||
+ | </source> | ||
+ | Plays the sound testmod_testsound.ogg at the postion 0,0,0. | ||
+ | |||
+ | |||
[[Category:Methods]] | [[Category:Methods]] |
Revision as of 14:16, 19 January 2013
Syntax
minetest.sound_play(SimpleSoundSpec, SoundParameters)
Description
Plays a sound.
Only OGG 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 hanlder that can be passed to minetest.sound_stop(handle)
to stop the sound.
Examples
minetest.sound_play("testmod_testsound", {
pos = {x=0, y=0, z=0},
max_hear_distance = 100,
gain = 10.0,
})
Plays the sound testmod_testsound.ogg at the postion 0,0,0.