Smooth Scrolling??

BlitzMax Forums/BlitzMax Beginners Area/Smooth Scrolling??

He is talking about using Delta time. Basically drawing on a time base rather than as fast as blitz can cycle


Quick code (not tested,just theory)
'Get time between now and last update
Delta = Millisecs() - LastTime

'Draw every 20 millsecs
ScrollDelta = Delta / 20
'^ float value

If Delta > 0 then LastTime = Millisecs()

NewX = OldX + (ScrollDelta * 16)


So say we want to move 100 pixels every 50 ms, then we take the time between now and the previous update, find a delta value for it (timechange / 50), and multiply it by our 100 pixel movement speed. If it was less than 50 ms between now and our last movement, then we move only at a fraction of the full distance, if it was more, then we move at a larger number... IE if only 25 ms passed, then we moved only 50 pixels, if 200 ms passed, then we moved 400 pixels.. This way the movement looks smooth (time based) and not jaggered (cycle based) because blitz doesnt cycle at a constant rate.