Smooth Scrolling??

BlitzMax Forums/BlitzMax Beginners Area/Smooth Scrolling??

FBEpyon(Posted 2005) [#1]
Hey everyone can someone help me get this code below to smooth scroll, right now its scrolling 1 tile (16 pixel) at a time. Am I missing something??


		For Local y = cloud_y To 13 + cloud_y
			For Local x = cloud_x To 15 + cloud_x
				SetBlend(ALPHABLEND) ; SetAlpha(.5) 
				DrawImage g_cloud,(x-cloud_x)*16,(y-cloud_y)*16,tilemap[x,y,2] ; SetBlend(SOLIDBLEND)	
				DrawText x,8,24			
			Next
		Next
	
' THIS BELOW IS THE TIMER TO MOVE THE TILES

	cloud_w = cloud_w + 1
	If cloud_w > 20
		If cloud_x < 15 Then cloud_x = cloud_x + 1 Else cloud_x = 0
		If cloud_y < 15 Then cloud_y = cloud_y + 1 Else cloud_y = 0
		cloud_w = 0
	EndIf



:EDIT:

Sorry forgot to mention, Im trying to do pixel scrollin, but retaining the maps tile array


Dreamora(Posted 2005) [#2]
you can add a * time_diff/1000 factor to the *16 or *tilesize you actually have where time_diff is the amount of millisecs between map redraw operation.


FBEpyon(Posted 2005) [#3]
Can you show me what your talking about please???


DH(Posted 2005) [#4]
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.


FBEpyon(Posted 2005) [#5]
Thanks all I got it to work :P


DH(Posted 2005) [#6]
What did you get to work?


DannyD(Posted 2005) [#7]
I get this error when compiling


Could you post the working source please :)


DH(Posted 2005) [#8]
lol, are you talking to FBEpyon?