I’m working on a game and sometimes very hard calculations need to be done whereafter my fps seriously drops.
Therefore I made a code to calculate the fps, but it doesn’t work. First I have a fps of for example 50, then 250 and then 130.
Why is my fps not a little bit constantly?
This is my code:
function calc_fps()
counter = counter + 1
if newtime<os.clock() then
fps=counter
newtime=os.clock()+1
counter=0
end
end
function setup()
end
function draw()
background(40,40,50)
-- Put an FPS counter in the corner of your screen
local fps = 1/DeltaTime
fill(255,255,255)
textMode(CORNER)
text(fps, 10, 10)
end
```
I recommend putting it in a string.format otherwise the number will jump around as the number of digits changes. Something like string.format("%.2f", 1/DeltaTime).