【发布时间】:2017-10-09 17:01:39
【问题描述】:
我正在编写一个应用程序,当您点击一个按钮时,它会增加倒数计时器的剩余时间,并增加计数器上的数字,以显示您已进行了多少次点击。我的问题是,当两个数字相等时,倒计时停止并且数字和计数器成为同义词。我需要改变什么/我做错了什么?
-- Create Button
local blueButton = display.newCircle (160,240,45)
blueButton:setFillColor(0,.5,1)
-- Create Tap-counter
local number = 0
local textField = display.newText(number, 160, 30, native.systemFont, 52)
-- Create Countdown Timer
local count = 20
local textCount = display.newText(count, 160, 70, native.systemFont, 52)
textCount:setFillColor(0,1,.25)
-- Create countdown function
local function countDown()
count = count - 1
textCount:removeSelf()
textCount = display.newText(count, 160, 70, native.systemFont, 52)
textCount:setFillColor(0,1,.25)
end
-- Create tap function
local function buttonTap(event)
number = number + 1
textField:removeSelf()
textField = display.newText(number, 160, 30, native.systemFont, 52)
count = count + 1
textCount:removeSelf()
textCount = display.newText(count, 160, 70, native.systemFont, 52)
textCount:setFillColor(0,1,.25)
end
-- Tapping button calls tap function
blueButton:addEventListener("tap", buttonTap)
-- countdown every second
timer.performWithDelay(1000, countDown, count)
【问题讨论】: