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
|