iDevGames Forums
TNTBasic: Getting the framerate - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Programming Languages & Scripting (/forum-8.html)
+--- Thread: TNTBasic: Getting the framerate (/thread-6885.html)



TNTBasic: Getting the framerate - death_himself - Jul 28, 2003 06:00 AM

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


TNTBasic: Getting the framerate - Steven - Jul 28, 2003 07:37 AM

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


TNTBasic: Getting the framerate - death_himself - Jul 28, 2003 07:40 AM

Oh, okay, thanks steven Smile ...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.


TNTBasic: Getting the framerate - Steven - Jul 28, 2003 07:52 AM

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.


TNTBasic: Getting the framerate - death_himself - Jul 28, 2003 08:02 AM

Oh, right, yes, thanks Smile, 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 Smile , thanks again.


TNTBasic: Getting the framerate - JAS__ - Aug 14, 2003 09:48 PM

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.