Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Fps calculation

edited February 2013 in General Posts: 7

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

By the way, sorry for my poor English :)

Tagged:

Comments

  • SimeonSimeon Admin Mod
    Posts: 5,387

    Hi, here is an easier way to calculate FPS:

    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
  • Posts: 2,161

    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).

  • edited February 2013 Posts: 52

    It also helps to mod Simeon's code to

    text(math.ceil(fps),10,10)
    
  • Posts: 7

    Thanks all of you. Now it works very well. :)

Sign In or Register to comment.