how to control frames per second (fps-rate)
Blitz3D Forums/Blitz3D Beginners Area/how to control frames per second (fps-rate)
| ||
I am familiar with darkbasic, and they have a Sync command, and sync rate command that can control the frame per second on a game. I am working on a scroller game in blitz3d (using 2d graphics) but it is running way to fast, and short of build some kind of while loop that counts miliseconds, i am trying to determine if there is a global command in blitz that can force a program to execute without going above a particular frame rate. thanks - sam |
| ||
Here's one way to do it... http://www.blitzbasic.com/codearcs/codearcs.php?code=9 |
| ||
that is using graphics3d if my game is only using 2d bitmaps/etc the update world etc and those commands would not be used? there stictly 3rd, aren't they? |
| ||
global timer const fps = 30; number of frames per second Repeat ;code goes here If Millisecs() - Timer > 1000/fps Timer = millisecs() Forever This should work. |
| ||
This is how I do it.Graphics 640,480,0,2 SetBuffer BackBuffer() HidePointer() FrameRateMax=CreateTimer(30) ;create a timer to cap the FPS While Not KeyHit(1) WaitTimer(frameRateMax) ; wait to make sure the framerate does not exceed the max framerate Rect MouseX(),MouseY(),10,10 Flip Cls Wend End What you do here is simply set the FrameRateMax timer to the frame rate you want things capped at. This will only cap the speed of a fast system, so a slow system will play slow, but it is a very easy way to lock frame rates. |
| ||
Oh for god's sake, I'll answer it. timer = createtimer(30) while not keydown(1) ;main loop waittimer timer wend end the timer ticks once every 30th of a second, so the game will not run faster than 30 frames per second, change this value as you see fit, remebering not to set it higher than 60 as this is most people screen refresh rate. |
| ||
@Andy, the post above you says exactly the same? |
| ||
guy this is not right. I can not tell what is the right way. cause i am also looking for it. But in you example you forget one thing. If you code is langer the waittimer () take always the time you give. but it il not take any consideration how long you code is. That means that you frame rate wil go down if the code wil be more. |
| ||
guy this is not right. You're correct. Using a timer is a very bad way to do this. I can not tell what is the right way. If you're working in 3D, the link Stayne provided to James' entry in the codearchives is a very good way to do it. |