【问题标题】:how to play a sound on a button click, only once in corona sdk?如何在按钮单击时播放声音,仅在电晕 sdk 中播放一次?
【发布时间】:2014-06-02 19:07:38
【问题描述】:

当用户点击按钮时,我只尝试播放一次声音,我该怎么做?

这是我到目前为止所做的,但是我该如何添加声音:

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
}

【问题讨论】:

    标签: sdk lua coronasdk


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多