To fast!!!

Blitz3D Forums/Blitz3D Beginners Area/To fast!!!

Pete Carter(Posted 2006) [#1]
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


jhocking(Posted 2006) [#2]
"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.


Pete Carter(Posted 2006) [#3]
ok ill reword that simplest to code?


Andy(Posted 2006) [#4]
>ok ill reword that simplest to code?

No coding needed

http://www.blitzbasic.com/codearcs/codearcs.php?code=9


Andy


Pete Carter(Posted 2006) [#5]
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


Matty(Posted 2006) [#6]
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)




Buggy(Posted 2006) [#7]
Pardon me, but what's delta time?


LineOf7s(Posted 2006) [#8]
Here's a great tutorial on delta time:

http://techknows.exsoftgames.com/forums/BC/cgi-bin/articles/show_article1722.html?f=gamemorduun03212002.html


jhocking(Posted 2006) [#9]
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.


Naughty Alien(Posted 2006) [#10]
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..