Difference between revisions of "love.timer.getFPS"

(Clarification.)
m
 
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
Returns the current frames per second.
+
{{newin|[[0.2.1]]|021|type=function}}
 +
Returns the current number of frames per second.
  
Displaying the FPS with [[love.graphics.print]] or [[love.graphics.setCaption]] can have an impact on this value. Keep this in mind while benchmarking your game.
 
 
== Function ==
 
== Function ==
 
=== Synopsis ===
 
=== Synopsis ===
Line 11: Line 11:
 
=== Returns ===
 
=== Returns ===
 
{{param|number|fps|The current FPS.}}
 
{{param|number|fps|The current FPS.}}
 +
=== Notes ===
 +
The returned value is the number of frames rendered during the last second, rounded to the nearest integer value.
 +
 +
It is one divided by what [[love.timer.getAverageDelta]] returns, otherwise known as the reciprocal, or multiplicative inverse of it.
 +
 +
To get instantaneous frame rate values, use <code>1.0 / love.timer.getDelta()</code>, or <code>1.0 / dt</code> if in [[love.update]], with <code>dt</code> given as the parameter.
 +
 +
== Examples ==
 +
Display text at the top left of the screen showing the current FPS.
 +
<source lang="lua">
 +
function love.draw()
 +
  love.graphics.print("Current FPS: "..tostring(love.timer.getFPS( )), 10, 10)
 +
end
 +
</source>
 
== See Also ==
 
== See Also ==
 
* [[parent::love.timer]]
 
* [[parent::love.timer]]

Latest revision as of 02:55, 21 October 2022

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

Returns the current number of frames per second.

Function

Synopsis

fps = love.timer.getFPS( )

Arguments

None.

Returns

number fps
The current FPS.

Notes

The returned value is the number of frames rendered during the last second, rounded to the nearest integer value.

It is one divided by what love.timer.getAverageDelta returns, otherwise known as the reciprocal, or multiplicative inverse of it.

To get instantaneous frame rate values, use 1.0 / love.timer.getDelta(), or 1.0 / dt if in love.update, with dt given as the parameter.

Examples

Display text at the top left of the screen showing the current FPS.

function love.draw()
   love.graphics.print("Current FPS: "..tostring(love.timer.getFPS( )), 10, 10)
end

See Also


Other Languages