如何使按钮在corona sdk中只按下一次而不重复按下?

如何使按钮在corona sdk中只按下一次而不重复按下?,sdk,lua,coronasdk,Sdk,Lua,Coronasdk,我正在制作一个问题应用程序,当你选择正确的答案按钮时,分数会增加+1,选择错误答案时,分数会增加-1, 我如何使按钮能够按一次,但之后不能再按?因为如果你一直按按钮,分数会不断增加 这是按钮1: local widget = require( "widget" ) local function handleButtonEvent( event ) if ( "ended" == event.phase ) then minusScore() print(

我正在制作一个问题应用程序,当你选择正确的答案按钮时,分数会增加+1,选择错误答案时,分数会增加-1, 我如何使按钮能够按一次,但之后不能再按?因为如果你一直按按钮,分数会不断增加

这是按钮1:

local widget = require( "widget" )


local function handleButtonEvent( event )

    if ( "ended" == event.phase ) then 
    minusScore()

        print( "Button was pressed and released" )
    end
end 

local button1 = widget.newButton
{
    width = 350,
    height = 360,
    left= 30,
    top= 220,
    defaultFile = "speakers.png",
    overFile = "wrong.png",
    --label = "button",
    onEvent = handleButtonEvent
}
这是分数函数。也许有一种方法,分数加1,然后停止:

-------------------得分------------------------

local score = 0
local scoreTxt = display.newText( "0", 0, 0, "Helvetica", 40 ) 
scoreTxt:setReferencePoint(display.TopLeftReferencePoint)
scoreTxt.x = display.screenOriginX + 700
scoreTxt.y = display.screenOriginY + 37
scoreTxt:setTextColor(2,2,2)
---------------------score added 10-----------------------------
function updateScore()
    score = score + 1
    _G.score = score
    scoreTxt.text = string.format(" %d", score)
end
local scoretimer = timer.performWithDelay(1, updateScore,1)
---------------------score minus 1-----------------------------
 function minusScore()
    score = score - 1
    _G.score = score
   scoreTxt.text = string.format(" %d", score)
end
local scoretimer = timer.performWithDelay(1, minusScore,1)

你可以这样做:

local minusButtonPressed = false

local function handleButtonEvent( event )
    if ( ( "ended" == event.phase ) and (minusButtonPressed == false) )  then 
        minusScore()
        print( "Button was pressed and released" )
        --disable the button
        minusButtonPressed = true
    end
 end

您可能还想将按钮的alpha值更改为.5,以显示在同一功能中已禁用。它起作用了!非常感谢你!从永远开始,我一直在努力寻找答案!在移动到下一个场景后,有没有办法阻止按钮被按下?是的,看看这个。在您的情况下,minusButtonPressed变量就是您要保存其状态的变量。有很多方法可以做到这一点,它们有不同的优点和缺点。