当按下按钮时,分数激活不工作,Corona sdk



我希望分数只在按下此按钮时增加。然而,当我尝试运行我的代码得分没有改变…什么好主意吗?提前感谢!

下面是我的代码:
score = 0

local scoreNumber = display.newText(score, 200, 30, nil, 20)
scoreNumber.xScale = 1.2
scoreNumber.yScale = 1.2

local scoreText = display.newText("score:", 150, 30, nil, 20)
scoreText.xScale = 1.2
scoreText.yScale = 1.2

local buttonPressed = false
local myButton = display.newRect(50,50,100,100)
local function scoretimer(event)
if buttonPressed then
    score = score + 1
    scoreNumber.text = score
    end
end
local function buttonPressed(event)
     if event.phase == "began" then
          buttonPressed = true
     elseif event.phase == "ended" then
          buttonPressed = false
     end
     return true
 end
 myButton:addEventListener("touch", buttonPressed)
 Runtime:addEventListener("enterFrame", scoretimer)

首先声明:

local buttonPressed = false

end,然后再次声明为函数:

local function buttonPressed(event)

重命名你的函数,一切都会好起来的

相关内容

  • 没有找到相关文章

最新更新