## TNTBasic: Getting the framerate

death_himself
Unregistered

Post: #1
Hi, I decided to try out TNTBasic whilst I wait for a book at my local library on carbon programming to come in...basically I'm just using TNTBasic to try out some game physics, I chose it because it does rotation...important if I want to do something more than straight-line physics. Anyway, whilst doing this I got stumped, you see, I need to find the fps so that no matter what computer it runs on or whatever other background tasks I have going on, my white square will still move the same amount of pixels in one second...if I'm making any sense whatsoever. Now I know I can set the framerate, but thats no good because the framerate will still vary, so the only thing I can do is 'set framerate max' ...but that is problematic because I need to actually get the framerate so I can do the simple calculation, and I can't just do 'int fps=set framerate max'...sorry, I know its a real simple question and prolly shouldn't be on here...but any help most appreciated .
Member
Posts: 370
Joined: 2002.04
Post: #2
Create two global variables (or whatever the TNT equivalent is). Set one to the current system time in whatever unit it gives you. The other should be increased every time you draw the frame. Whenever you want the FPS, divide the frame counter by the time. Thats how many average frames you've achieved per millisecond, second, or whatever time unit the time function you use gives. You can adjust to seconds fairly easily.
Steven

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
death_himself
Unregistered

Post: #3
Oh, okay, thanks steven ...thought I had to do something like that, but weren't sure, what with TNT's own calls I thought I had to use them to do everything.
Member
Posts: 370
Joined: 2002.04
Post: #4
Oh, oops, one more thing - when you divide the frames by the time, you should divide by the time elapsed instead. Ex:
Code:
`fps = frameCounter / (startTime - currentTimeMillis)`

That's not TNT code - you'll have to replace currentTimeMillis by whatever you call to get the current time.

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
death_himself
Unregistered

Post: #5
Oh, right, yes, thanks , I knew what you meant first time round though. Don't quite understand why TNTBasic has a facility to show the fps but yet, doesn't let you use it for your own use, only it's. If I'm making any sense. Anyway, I'll do what you said , thanks again.
JAS__
Unregistered

Post: #6
You can just hit escape while running a game and select fps fromt the menu, too. Instead of all (ok, not that much) the math and hit escape to return to the game.