Difference between revisions of "love.timer.getAverageDelta"

m (Fixed example)
m (Added links to update and draw callbacks.)
 
Line 12: Line 12:
 
{{param|number|delta|The average delta time over the last second.}}
 
{{param|number|delta|The average delta time over the last second.}}
 
== Examples ==
 
== Examples ==
Display text at the top left of the screen showing the average time taken to update and draw each frame.
+
Display text at the top left of the screen showing the average time taken to [[love.update|update]] and [[love.draw|draw]] each frame.
 
<source lang="lua">
 
<source lang="lua">
 
function love.draw()
 
function love.draw()

Latest revision as of 10:04, 2 October 2014

Available since LÖVE 0.9.0
This function is not supported in earlier versions.

Returns the average delta time (seconds per frame) over the last second.

Function

Synopsis

delta = love.timer.getAverageDelta( )

Arguments

None.

Returns

number delta
The average delta time over the last second.

Examples

Display text at the top left of the screen showing the average time taken to update and draw each frame.

function love.draw()
   local delta = love.timer.getAverageDelta()
   -- Display the frame time in milliseconds for convenience.
   -- A lower frame time means more frames per second.
   love.graphics.print(string.format("Average frame time: %.3f ms", 1000 * delta), 10, 10)
end

See Also

Other Languages