Difference between revisions of "Sound"
From GiderosMobile
(3 intermediate revisions by 2 users not shown) | |||
Line 12: | Line 12: | ||
=== Example === | === Example === | ||
'''Play a background music in loop''' | '''Play a background music in loop''' | ||
− | < | + | <syntaxhighlight lang="lua"> |
--local sound = Sound.new("bgmusicloop.wav") | --local sound = Sound.new("bgmusicloop.wav") | ||
local sound = Sound.new("bgmusicloop.mp3") | local sound = Sound.new("bgmusicloop.mp3") | ||
Line 41: | Line 41: | ||
-- channel:setPitch(1.5) | -- channel:setPitch(1.5) | ||
end) | end) | ||
− | </ | + | </syntaxhighlight> |
=== See also === | === See also === | ||
+ | '''[[SoundChannel]]'''<br/> | ||
'''[[Playing_Sound_and_Music]]''' | '''[[Playing_Sound_and_Music]]''' | ||
Line 49: | Line 50: | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
=== Methods === | === Methods === | ||
− | [[Sound.new]] ''creates a new Sound object''<br/><!--GIDEROSMTD:Sound.new(filename) creates a new Sound object--> | + | [[Sound.new]] ''creates a new Sound object from a file''<br/><!--GIDEROSMTD:Sound.new(filename) creates a new Sound object from a file--> |
+ | [[Sound.new]] ''creates a new Sound object from a table''<br/><!--GIDEROSMTD:Sound.new(data,rate,stereo) creates a new Sound object from a table--> | ||
[[Sound.setListenerPosition]] ''sets the position, velocity and orientation of the listener''<br/><!--GIDEROSMTD:Sound.setListenerPosition(x,y,z,vx,vy,vz,dx,dy,dz,ux,uy,uz) sets the position, velocity and orientation of the listener--> | [[Sound.setListenerPosition]] ''sets the position, velocity and orientation of the listener''<br/><!--GIDEROSMTD:Sound.setListenerPosition(x,y,z,vx,vy,vz,dx,dy,dz,ux,uy,uz) sets the position, velocity and orientation of the listener--> | ||
[[Sound:getLength]] ''gets the sound duration''<br/><!--GIDEROSMTD:Sound:getLength() gets the sound duration--> | [[Sound:getLength]] ''gets the sound duration''<br/><!--GIDEROSMTD:Sound:getLength() gets the sound duration--> | ||
Line 55: | Line 57: | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
+ | |||
=== Events === | === Events === | ||
=== Constants === | === Constants === |
Latest revision as of 06:41, 31 August 2023
Supported platforms:
Available since: Gideros 2011.6
Inherits from: Object
Description
The Sound class lets you load and play WAV, MP3, MOD, XM, S3M and IT sound files.
Control of the playing sound is performed through the SoundChannel object.
Example
Play a background music in loop
--local sound = Sound.new("bgmusicloop.wav")
local sound = Sound.new("bgmusicloop.mp3")
print(sound:getLength())
local channel = sound:play(26000, true, false)
print(channel:getPosition())
channel:setPosition(20000)
print(channel:getPosition())
channel:setPaused(false)
channel:addEventListener(Event.COMPLETE, function() print("complete") end)
local function onTimer()
-- print(channel:getPosition(), sound:getLength())
collectgarbage()
end
local t = Timer.new(100)
t:addEventListener(Event.TIMER, onTimer)
t:start()
stage:addEventListener(Event.MOUSE_DOWN, function()
channel:setPaused(not channel:isPaused())
channel:setPosition(10000)
-- channel:setPitch(1.5)
end)
See also
SoundChannel
Playing_Sound_and_Music
MethodsSound.new creates a new Sound object from a file |
EventsConstants |