Scrolling background?

Blitz3D Forums/Blitz3D Beginners Area/Scrolling background?

zortzblatz(Posted 2009) [#1]
How can I make a background scroll? Below you will find the code
I already have for this endevor. In this program the image just sort of floats right until it is off the screen, then reappears in it's initial position. But it doesn't loop around, that is to say as it moves, it does not appear behind itsself, it leaves blackness.

Graphics 800,600


Global manwalk = LoadAnimImage("fwalk.bmp",180,270,0,6)
Global manwalkr = LoadAnimImage("bwalk.bmp",180,270,0,6)


ScaleImage manwalk,.5,.5
MaskImage manwalk,255,0,0
MidHandle manwalk
Global tmrSparks, frmSparks

Global bg = LoadImage("bg2.bmp")
ResizeImage bg,800,600
MidHandle bg 


ScaleImage manwalkr,-.5,.5
MaskImage manwalkr,255,0,0
MidHandle manwalkr

Type player
Field image
Field life
Field attacking
End Type

p.player = New player
p\image = manwalk
TileImage bg,0,0
x = 0
While Not KeyHit(1)

;MidHandle manwalk


Walk()
BackGround()
 
DrawImage bg,400+x,300

x=x+1

If x >= ImageWidth(bg)
x = 0
EndIf

DrawImage p\image,400,400,frmSparks



Flip
Cls

Wend



Function BackGround()



End Function









Function Walk()
If KeyDown(203) Then

For play.player = Each player
play\image = manwalk
Next



If MilliSecs() > tmrSparks + 100 Then
tmrSparks=MilliSecs()
frmSparks=(frmSparks+1) Mod 6
End If
End If

If KeyDown(205) Then

For play.player = Each player
play\image = manwalkr
Next

If MilliSecs() > tmrSparks + 100 Then
tmrSparks=MilliSecs()
frmSparks=(frmSparks+1) Mod 6
End If
End If

End Function



Matty(Posted 2009) [#2]
Try using tileimage instead of drawimage - assuming your background is tileable...ie something simple like just grass etc.


zortzblatz(Posted 2009) [#3]
That worked, I didn't realize tiling it drew it. Is there any way to eliminate the border around the image?


Matty(Posted 2009) [#4]
You need to make the image 'seamless'.


zortzblatz(Posted 2009) [#5]
How do I do that?


D4NM4N(Posted 2009) [#6]
Another easy cheaty way to get a scrolling background is by using a skybox. :)


Matty(Posted 2009) [#7]
Hi D4NM4N - I don't understand - how does using a skybox work (or help) in a 2d scrolling game?