如何在Corona SDK中使按钮只被按一次而不是反复按下?

我正在制作一个问题应用程序,当您选择正确的答案按钮时,将+1添加到分数中,选择错误答案时则将-1, 我该如何使按钮能够只能按一次,然后再也不能按了?因为如果您不断按按钮,分数会不断增加!

这是button1:

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然后停止:

-------------------score------------------------

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)
点赞
用户2333874
用户2333874

你可以像这样做:

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
2014-05-26 16:42:03