10.03.2019 - Round 1 results of our "A Love Letter For FreeBASIC" game dev competition have been published. Please be sure to check the results thread: http://games.freebasic.net/forum/index.php?topic=629.0. Don't forget that the competition is continuing with a round 2, lasting till 29th of April, 300 USD first prize. Stay tuned!

Author Topic: FPS counter  (Read 3168 times)

darkhog

  • Recruit
  • **
  • Posts: 21
    • View Profile
FPS counter
« on: October 14, 2011, 11:21:40 AM »
How to make one? Currently my program's main loop look like that:

Code: [Select]
do
do_drawing
do_logic
sleep 1000/MAX_FPS,1 ' MAX_FPS is constant currently set to 60
loop

But want to check framerate to see how much I can do at once.

ecxjoe

  • Novice
  • ***
  • Posts: 78
    • View Profile
    • Delta Code
Re: FPS counter
« Reply #1 on: October 14, 2011, 07:49:50 PM »
Instead of using a sleep statement, try this: http://deltacode.blogspot.com/2009/07/delay-factor.html

When you have that working, all you need is a fps variable that increments by one in your game loop and have it reset to zero every second using an on-timer function.

Lachie Dazdarian

  • Double dipper
  • Administrator
  • Forum Sage
  • *****
  • Posts: 1308
    • Yahoo Instant Messenger - lachie13
    • View Profile
    • The Maker Of Stuff
    • Email
Re: FPS counter
« Reply #2 on: October 15, 2011, 03:48:06 AM »
Declare these variables:

Code: [Select]
DIM SHARED AS INTEGER FPS, FPS2
DIM SHARED AS DOUBLE Starttime

Put this in your loop:

Code: [Select]
FPS = FPS + 1                     ' Used to count FPS.
IF StartTime + 1 < TIMER THEN
 FPS2 = FPS
 FPS = 0
 StartTime = TIMER
END IF

Print FPS2 to show FPS.

You have that in the scrolling engine I gave you, btw.
"Things like Basic and Free Basic provide much-needed therapy and a return to sanity and a correct appreciation of people. The arrogant folk really hate a word like 'Basic' - fine, and good riddance." ~ pragmatist