I offer an alternative method.
Code: Select all
function love.load()
stime = love.timer.getTime()
end
function love.update(dt)
time = stime - love.timer.getTime()
end
function love.draw()
love.graphics.print(math.floor(time).." seconds have passed",0,12)
end
At least this method works in 0.5.0. As long as 0.6.0 still uses
getTime() to return the seconds since application launch.
And a bonus, a function that converts seconds into hours, minutes and seconds that I wrote myself:
Code: Select all
function formatTime(t) return math.floor(math.mod(t/60/60,60)) .. ":" .. string.sub("0" .. math.floor(math.mod(t/60,60)),-2) .. ":" .. string.sub("0" .. math.floor(math.mod(t,60)),-2) end
I used this method for my game engine to calculate how much total time you spent in a single game session between saves. You know like how RPG's will display total play time.
Use this when setting up the game variables:
Code: Select all
gameStartTime = love.timer.getTime()
Then use this when you load a game right after loading the game, or set it to 0 if starting a new one: (Usually right in the same function)
Use this every update during the actual game play:
Code: Select all
gameSession = love.timer.getTime() - gameStartTime
When saving the game, save the
gameSession variable for loading next time.