Newbie question: Audio
Posted: Thu Mar 20, 2014 4:10 pm
Hi,
I'm new to love and lua and am trying to create a simple program that registers a key press and plays a sound immediately when a key is pressed. However, I've noticed that after the first time I press a key and the sound plays, I have to wait a short duration before pressing again and hearing the sound. If I press the key too early after the first time, the sound will only play once and not twice. Any input/suggestions would be helpful. Cheers!
My Code:
I'm new to love and lua and am trying to create a simple program that registers a key press and plays a sound immediately when a key is pressed. However, I've noticed that after the first time I press a key and the sound plays, I have to wait a short duration before pressing again and hearing the sound. If I press the key too early after the first time, the sound will only play once and not twice. Any input/suggestions would be helpful. Cheers!
My Code:
Code: Select all
function love.load()
kicksrc = love.audio.newSource("kick.wav", "static")
kicksrc:setLooping(false)
end
function love.update()
--onKeyPressPlayAudio("d", kicksrc)
end
function love.draw()
onKeyDraw( "d", "d", "D", 50, 50 )
end
function onKeyDraw(keypress, textDefault, textPressed, x, y)
if love.keyboard.isDown(keypress) then
love.graphics.print(textPressed, x, y)
else
love.graphics.print(textDefault, x, y)
end
end
function love.keypressed(key)
if key == "escape" then
love.event.quit()
end
if key == 'd' then
love.audio.play(kicksrc)
end
end