How to play sound one time?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
How to play sound one time?
Hello guys, how to play sound one time(in function love.update)?
Re: How to play sound one time?
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
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: How to play sound one time?
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
Who is online
Users browsing this forum: Bing [Bot] and 1 guest