Ich habe diesen Code von Rob Miracle von GitHub verwendet. Es funktioniert gut, aber mein Problem ist, dass, wenn es 00:00 oder negativ erreicht, es meiner Anweisung folgt, zu einer anderen Szene zu gehen, aber es wird immer noch aktualisiert.Wie Stoppuhr wenn unter oder gleich 0 Corona SDK
local secondsLeft = 2 * 60 -- 2 minutes * 60 seconds
local clockText = display.newText("02:00", 280, 1, native.systemFontBold, 25)
clockText:setFillColor(1, 0, 0)
local function updateTime()
-- decrement the number of seconds
secondsLeft = secondsLeft - 1
-- time is tracked in seconds. We need to convert it to minutes and seconds
local minutes = math.floor(secondsLeft/60)
local seconds = secondsLeft % 60
-- make it a string using string format.
local timeDisplay = string.format("%02d:%02d", minutes, seconds)
clockText.text = timeDisplay
end
-- run them timer
local countDownTimer = timer.performWithDelay(1000, updateTime, secondsLeft)
Was noch aktualisiert? Deine Frage ist unklar. –
Ich habe diesen Code: if timedisplay <= "00:00" dann \t \t \t print "Game Over" \t \t \t Gameover() \t \t Ende habe ich versucht, die Zeit zu verfolgen, aber wen geht es um die Funktion Spiel vorbei, es wird immer noch dekrementiert. – int21h
Ich überprüfe deinen Code. Es funktioniert gut. Das Textobjekt wird nicht aktualisiert, nachdem die Zeit "00:00" erreicht wurde. – ldurniat