smooth scroll

Blitz3D Forums/Blitz3D Programming/smooth scroll

Trying to get smooth scrolling for a 2D game in Blitz 3D, but whatever I do, there is always a bit of jerkiness. The scrolling dowsn't appear smooth to me, and somtimes, it will give a noticeable jerk. I also want the screen to scroll slower than it is, but can't get this to work.

Can anyone give any suggestions as to why it's not working?

Thanks

Code below...




Global Debug = True


Type FrameRate
Field TargetFPS#
Field SpeedFactor#
Field TimeElapsed#
Field FPS#
Field FPS2#
Field FPS3#
Field FPS4#
Field FPS5#
Field CurrentTicks
Field FrameDelay
End Type

Global no0# = 0.00000000001 ;avoids division by zero
;for example; any time you perform a division, add no0# to the divisor
;quotient# = dividend# / (divisor# + no0#)

Global FL.FrameRate = New FrameRate

;initialize frame limiter
FL\TargetFPS# = 60 ;set this to whatever FPS your code is based on
FL\FrameDelay = MilliSecs()


Graphics 800,600
quitgame=0



SetBuffer frontbuffer()

backx=0
backy=0
background=createimage(800,600)
SetBuffer ImageBuffer(background)
Color 255,0,0
Rect 0,0,50,50,1
Color 0,255,0
Rect 20,20,50,50,1

SetBuffer BackBuffer()




;---------------------------------------------------------------------------------------
; Main Game Loop **********************************************************************
;---------------------------------------------------------------------------------------


While (Not quitgame)

Cls

;Set Speed Factor
FL\CurrentTicks = MilliSecs()
FL\SpeedFactor# = (FL\CurrentTicks - FL\FrameDelay) / (1000.0 / FL\TargetFPS#)
If FL\SpeedFactor# <= 0 Then FL\SpeedFactor# = no0#
FL\TimeElapsed# = (FL\CurrentTicks - FL\FrameDelay) / 1000.0
If Debug
FL\FPS# = (FL\FPS2# + FL\FPS3# + FL\FPS4# + FL\FPS5# + FL\TargetFPS# / FL\SpeedFactor#) / 5
FL\FPS5# = FL\FPS4# : FL\FPS4# = FL\FPS3# : FL\FPS3# = FL\FPS2# : FL\FPS2# = FL\FPS#
EndIf
FL\FrameDelay = FL\CurrentTicks
;SpeedFactor# contains a percentage of the last frame
;TimeElapsed# contains a percentage of the last second
v# = v# + (FL\TimeElapsed# * a#) ;velocity (m/s) = velocity (m/s) + time (s) * acceleration (m/s^2)


speedZ=(FL\SpeedFactor#)




;--- check for escape key
If KeyDown( 1 )=True Then
quitgame =1
End if




;--- draw background...
For by=0 To 15
For bx=0 To 15
DrawImageRect background,backx+bx*50,backy+by*50,0,0,50,50
Next
Next



;-- scroll background down...
backy=backy+speedZ
If backy>700 Then backy=-800


If Debug
Text 10, 10, "FPS: " + Int(FL\FPS#)
Text 10,50,"X:"+Str$(backx)+" Y:"+Str$(backy)
EndIf


VWait
Flip False




Wend



End