我正在制作一个问题应用,当你选择正确的答案按钮时,+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然后停止的方式:
-------------------得分------------------------
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)
答案 0 :(得分: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