scrolling and delta time

BlitzMax Forums/BlitzMax Beginners Area/scrolling and delta time

hub(Posted 2006) [#1]
Hi !
Is somebody have experimented a tiled scrolling game, with delta time applied to the scrolled tiles ( (1 pixel * Delta) ? Perhaps it's better to choose another technic ? for the moment i not obtain good results... Thanks to report your experimentation or idea here !!!


smilertoo(Posted 2006) [#2]
at the moment im just assuming 60hz vsync.


TomToad(Posted 2006) [#3]
It depends mainly on how Delta is calculated. The simplest way is to make Delta equal to how many milliseconds have passed with something like this
NewTime = Millisecs()
Delta = NewTime - OldTime
OldTime = NewTime

Then you would multiply that by a factor which is determined by how much you want something to move each millisecond. For example, if you want the screen to scroll 100 pixels per second, that'll be 0.1 pixels per millisecond. Since you will be using fractional numbers, you must make sure your variables are declared as real with #,Float, or double.
ScrollX# :+ 0.1 * Delta

If you don't decalre the variables as real, then most likely your objects won't be updated properly, if at all.
Now there are a couple of disadvantages to this method, one being that when the internal clock rolls over, which happens when the computer hasn't been rebooted in several days, then you have to start dealing with negative Delta. Also, if some background task starts hogging the CPU, you will get sudden jerks in the animation. There are algorithms floating around that will take care of both problems, just do a search.


hub(Posted 2006) [#4]
Thanks TomToad for your explanations. Just a link to my previous try to use delta time...

http://www.bayre.com/zigwigwis/scroll.exe


Grey Alien(Posted 2006) [#5]
hub: Haven't you got my email yet? You had a few bugs in the way you tried to use it :-) I fixed them all and emailed it back.


hub(Posted 2006) [#6]
hi grey i've received your e-mail with your fix. Many thanks for your help again. Your bmax game framework is very usefull for us !