Code: Select all
function love.load()
time_passed = 0
end
function love.update(dt)
time_passed = time_passed + dt
end
function love.draw()
love.graphics.print("You've been playing for " .. time_passed .. " seconds.", 5, 45)
end
Code: Select all
function love.load()
time_passed = 0
end
function love.update(dt)
time_passed = time_passed + dt
end
function love.draw()
love.graphics.print("You've been playing for " .. time_passed .. " seconds.", 5, 45)
end
Code: Select all
function love.load()
time_passed = 0
end
function love.update(dt)
time_passed = time_passed + dt
end
function love.draw()
love.graphics.print("You've been playing for " .. math.floor(time_passed) .. " seconds.", 5, 45)
end
Code: Select all
time_passed = math.floor(love.timer.getTime())
Code: Select all
love.graphics.print("You've been playing for " .. math.floor(love.timer.getTime()).. " seconds.", 5, 45)
I did that and it did exactly what I wanted.love.graphics.print("You've been playing for " .. math.floor(love.timer.getTime()).. " seconds.", 5, 45)
If this time_passed variable was used for something else (like calculating player's position), then that would be a bad advice, because the game would not be smooth anylonger.mcjohnalds45 wrote:Use love.timer.getTime() to return the seconds since startup and math.floor() to round it down to a whole number, so change line six to:
Code: Select all
time_passed = math.floor(love.timer.getTime())
And that is the correct solution.mcjohnalds45 wrote: Or alternatively in this case just change line ten to the following and forget about time_passed.
Code: Select all
love.graphics.print("You've been playing for " .. math.floor(love.timer.getTime()).. " seconds.", 5, 45)
Code: Select all
function love.load()
start = love.timer.getTime()
end
function love.draw()
love.graphics.print("You've been playing for " .. math.floor(love.timer.getTime() - start).. " seconds.", 5, 45)
end
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests