Reputation: 7
im trying to paly a sound only once when user clicks on the button how can i do that?
here is what i have done so far, but how can i add the sound:
local widget = require( "widget" )
--button performed only once
local minusButtonPressed = false
local function handleButtonEvent( event )
if ( ( "ended" == event.phase ) and (minusButtonPressed == false) and (afterCorrect == false)) then
minusScore()
print( "Button was pressed and released" )
--disable the button
minusButtonPressed = true
end
end
local button1 = widget.newButton
{
width = 350,
height = 360,
left= 30,
top= 220,
defaultFile = "speakers.png",
overFile = "wrong.png",
--label = "button",
onEvent = handleButtonEvent
}
Upvotes: 0
Views: 956
Reputation: 60
I don't know if it's what you need for your programm, but try to include the audio lib and use
local laserSound = audio.loadSound( "laserBlast.wav" ) //init the sound
local laserChannel = audio.play( laserSound ) //play the sound once complete
Upvotes: 1