To fast!!!
Blitz3D Forums/Blitz3D Beginners Area/To fast!!!
| ||
Ive looked at alot of code examples and posts on timers and delta timing tweening etc, but im just wanting to make sure my game doent run faster on a better machine. whats the best way of limiting frames per second. ive just tryed my code on a friends new pc and it shoots along at twice the speed of my machine and is unplayable. Pete |
| ||
"Best" is a relative term. Me, I pretty much always use delta time for 3D stuff, although for 2D stuff sometimes I'm lazy and just use WaitTimer; it's inefficient use of computer power, but it's so damn easy. I never bothered to figure out tweening. That said, there are at least as many people who hate delta time as swear by it. Try a couple different methods and see which works best for you. Honestly, I don't think there's ultimately much difference between the various methods, it just comes down to which you are best able to understand. |
| ||
ok ill reword that simplest to code? |
| ||
>ok ill reword that simplest to code? No coding needed http://www.blitzbasic.com/codearcs/codearcs.php?code=9 Andy |
| ||
thanks i cant beleave i missed that? good thing its not to hard to get this into my code as ive left it right to the end :OP Pete |
| ||
A really easy way is to do this:;in your core loop you may have something like this: StartTime=millisecs() UpdateGameStuff() updateworld renderworld flip ;all you need to do is this here: repeat until millisecs()-StartTime>1000.0/float(FrameRateDesired) |
| ||
Pardon me, but what's delta time? |
| ||
Here's a great tutorial on delta time: http://techknows.exsoftgames.com/forums/BC/cgi-bin/articles/show_article1722.html?f=gamemorduun03212002.html |
| ||
Long story short, you figure out how much time has passed since last frame, and that value (the titular delta time) is multiplied with, well, pretty much everything in your code. This way everything happening in your code scales to the framerate. So for example, if an object is moving 1 unit per millisecond (very fast) and 15 milliseconds have elapsed since last frame, then you should increment the object's position by 15 units. The main gotcha, and it's not very complicated once you know to do this, is that you want to average out the deltas so that you don't get jittering due to occasional minor lags and spikes in the framerate. |
| ||
put this before your main loop frametimer=CreateTimer(60);60 is FPS you want stable on faster machines and put this in main loop WaitTimer(frametimer) enjoy.. |