-
Notifications
You must be signed in to change notification settings - Fork 2
Sound
ACharLuk edited this page Jan 21, 2018
·
1 revision
-
There is one more class we haven't used until now, the
soundclass. It gives you the ability to load sounds and play/pause/stop them. -
The usage is really simple, here's an example:
local mySound
...
function setup()
...
mySound = sound:new{ path = "path/to/sound/exampleSound.wav" }
end
function render()
...
end
function input()
if keys['Z'] then
mySound:play()
end
if keys['X'] then
mySound:pause()
end
if keys['C'] then
mySound:stop()
end
end-
This code plays the sound "path/to/sound/exampleSound.wav" when you press 'Z', pauses it when you press 'X' and stops it when you press the 'C' key.
-
You can also start playing a sound in the
setupfunction, this is useful if you want music always playing in your game.
- Fabulous! You can use the sound class now!
-
Tutorials