how would i end the game when the time runs out on the game
A basic structure:
[lua]
local gameActive = true
local gameTime = 30 – number of seconds to play game
local gameTimer = system.getTimer()
local gameOver = false
local gameLoop = function ()
if gameActive then
– do stuff to do with the game
local t =system.getTimer()
if t - gameTimer > 1000 then – a second has passed
gameTime = gameTime - 1 – decrement time left in game
gameTimer = system.getTimer()
if gameTime == 0 then
gameActive = false – time up, game over
end
end
else
if gameOver == false then
– do stuff when the game has ended
gameOver = true – make sure this code only runs once
end
end
end
Runtime:addEventListener(“enterFrame”,gameLoop)
[/lua]
[lua]
local timeLimit = 60
timeLeft = display.newText(timeLimit, 440, 30, native.systemFontBold, 40)
timeLeft:setTextColor(255,0,0)
local function timerDown()
timeLimit = timeLimit-1
timeLeft.text = timeLimit
if(timeLimit==0)then
print(“Time Out”) – or do your code for time out
end
end
timer.performWithDelay(1000,timerDown,timeLimit)
[/lua]
thats the code i have
A basic structure:
[lua]
local gameActive = true
local gameTime = 30 – number of seconds to play game
local gameTimer = system.getTimer()
local gameOver = false
local gameLoop = function ()
if gameActive then
– do stuff to do with the game
local t =system.getTimer()
if t - gameTimer > 1000 then – a second has passed
gameTime = gameTime - 1 – decrement time left in game
gameTimer = system.getTimer()
if gameTime == 0 then
gameActive = false – time up, game over
end
end
else
if gameOver == false then
– do stuff when the game has ended
gameOver = true – make sure this code only runs once
end
end
end
Runtime:addEventListener(“enterFrame”,gameLoop)
[/lua]
[lua]
local timeLimit = 60
timeLeft = display.newText(timeLimit, 440, 30, native.systemFontBold, 40)
timeLeft:setTextColor(255,0,0)
local function timerDown()
timeLimit = timeLimit-1
timeLeft.text = timeLimit
if(timeLimit==0)then
print(“Time Out”) – or do your code for time out
end
end
timer.performWithDelay(1000,timerDown,timeLimit)
[/lua]
thats the code i have