Difference between revisions of "love.timer.getAverageDelta"

m
m (Added links to update and draw callbacks.)
 
(One intermediate revision by one other user not shown)
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()
Line 18: Line 18:
 
   -- Display the frame time in milliseconds for convenience.
 
   -- Display the frame time in milliseconds for convenience.
 
   -- A lower frame time means more frames per second.
 
   -- A lower frame time means more frames per second.
   love.graphics.print(string.format("Average frame time: %.3f ms", 1000 * delta) 10, 10)
+
   love.graphics.print(string.format("Average frame time: %.3f ms", 1000 * delta), 10, 10)
 
end  
 
end  
 
</source>
 
</source>

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