我试图只在用户点击按钮时播放一次声音我该怎么做?
这是我到目前为止所做的,但我怎样才能添加声音:
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
}
答案 0 :(得分:1)
我不知道你的程序是否需要它,但尝试包含音频库 并使用
local laserSound = audio.loadSound( "laserBlast.wav" ) //init the sound
local laserChannel = audio.play( laserSound ) //play the sound once complete