Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何播放一个按钮点击的声音,只有一次在电晕sdk?_Sdk_Lua_Coronasdk - Fatal编程技术网

如何播放一个按钮点击的声音,只有一次在电晕sdk?

如何播放一个按钮点击的声音,只有一次在电晕sdk?,sdk,lua,coronasdk,Sdk,Lua,Coronasdk,当用户点击按钮时,我只想播放一次声音,我怎么能做到 以下是我到目前为止所做的工作,但如何添加声音: local widget = require( "widget" ) --button performed only once local minusButtonPressed = false local function handleButtonEvent( event ) if ( ( "ended" == event.phase ) and (minusButtonPressed

当用户点击按钮时,我只想播放一次声音,我怎么能做到

以下是我到目前为止所做的工作,但如何添加声音:

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
}

我不知道这是否是您的程序所需要的,但请尝试包含音频库 和使用

local laserSound = audio.loadSound( "laserBlast.wav" ) //init the sound 
local laserChannel = audio.play( laserSound )  //play the sound once complete