How to play sound one time?
Posted: Sat Oct 11, 2014 3:01 pm
Hello guys, how to play sound one time(in function love.update)?
Code: Select all
local sound = love.audio.newSource(filename)
local play = true
love.update = function(dt)
if play then
sound:play()
play = false
end
end
Ok, Thanks=)Nixola wrote:You can trigger the play function just once, maybe using a boolean:
This will load the sound and create a variable once. Then, every frame, it checks if the variable is true: if so, it plays the sound and sets it to false, so that it doesn't happen again.Code: Select all
local sound = love.audio.newSource(filename) local play = true love.update = function(dt) if play then sound:play() play = false end end