HI, I would like to know how to create a stop watch that count from 0 to the infinite to include in my game.
Thanks ^^ [import]uid: 129238 topic_id: 25077 reply_id: 325077[/import]
HI, I would like to know how to create a stop watch that count from 0 to the infinite to include in my game.
Thanks ^^ [import]uid: 129238 topic_id: 25077 reply_id: 325077[/import]
Hey there, please don’t make duplicate threads. (I’ve just deleted your other one.)
For your stop watch try running this code on its own for an example;
[lua]local totalTime = 0
local myText = display.newText(“Hello World!”, 150, 100, native.systemFont, 16)
local function updateTime()
totalTime = totalTime + 1
myText.text = totalTime
end
myTimer = timer.performWithDelay(100, updateTime, 0)
local stopBtn = display.newCircle( 160, 300, 40 )
local function stop()
timer.cancel(myTimer)
end
stopBtn:addEventListener(“tap”, stop)[/lua]
Peach
[import]uid: 52491 topic_id: 25077 reply_id: 102073[/import]
Thanks! but I was wondering how it is possible to create a stopwatch with hour, minutes and seconds like “00:00:01”, “00:14:29”, “01:24:33”, not just with seconds, how can I do that? anyway thanks for your help
[import]uid: 129238 topic_id: 25077 reply_id: 102334[/import]
Here is one way to do it.
Left button starts and stops the timer, right button resets the timer
[code]
local seconds = 0
local minutes = 0
local hours = 0
local secDisplay = “”
local minDisplay = “”
local hourDisplay = “”
local start = true
local myText = display.newText(“00:00:00”, 150, 100, native.systemFont, 64)
local function updateTime()
seconds = seconds + 1
if seconds > 59 then
minutes = minutes + 1
seconds = 0
end
if minutes > 59 then
hours = hours + 1
minutes = 0
end
if seconds < 10 then
secDisplay = “:0”
else
secDisplay = “:”
end
if minutes < 10 then
minDisplay = “:0”
else
minDisplay = “:”
end
if hours < 10 then
hourDisplay = “0”
else
hourDisplay = “”
end
myText.text = hourDisplay…hours…minDisplay…minutes…secDisplay…seconds
end
local startBtn = display.newCircle( 160, 300, 40 )
local resetBtn = display.newCircle( 320, 300, 40 )
local function startWatch()
if start == true then
myTimer = timer.performWithDelay(1000, updateTime, 0)
start = false
elseif start == false then
timer.cancel(myTimer)
start = true
end
end
local function reset()
seconds = 0
minutes = 0
hours = 0
myText.text = “00:00:00”
end
startBtn:addEventListener(“tap”, startWatch)
resetBtn:addEventListener(“tap”, reset)
[/code] [import]uid: 129287 topic_id: 25077 reply_id: 102341[/import]
It finally work!
[import]uid: 129238 topic_id: 25077 reply_id: 102801[/import]