Im trying to make the backgound scroll. But one of the images flashes! How can i fix this?
Printable View
Im trying to make the backgound scroll. But one of the images flashes! How can i fix this?
Try using pic boxes instead, and instead of moving the objects paint the image to the area, something like this (file attached).
Code:Option Explicit
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Sub Timer_Timer()
Static ImgLeft As Long
Picture2.Cls
BitBlt Picture2.hDC, ImgLeft, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hDC, 0, 0, vbSrcCopy
BitBlt Picture2.hDC, Picture1.ScaleWidth + ImgLeft, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hDC, 0, 0, vbSrcCopy
Picture2.Refresh
ImgLeft = ImgLeft - 4
If ImgLeft <= -Picture1.ScaleWidth Then ImgLeft = 0
End Sub
Private Sub Form_Load()
' source
Picture1.ScaleMode = vbPixels
Picture1.AutoRedraw = True
Picture1.Visible = False
' destination
Picture2.ScaleMode = vbPixels
Picture2.AutoRedraw = True
Picture2.Move 0, 0, Picture1.Width, Picture1.Height
End Sub
Works great, Edge.
Dumb question: where is your image stored/referenced?
I'd like to steal this for a game I made for my kids, but can't figure out how to sub my background for yours! Probably obvious, but I'm only on my first cup of (bad) coffee this morning!
Bryce
Picture1 holds the source image, you'll probably want to set the source to autoresize also, maybe something like,,.,
Code:
Private Sub Form_Load()
' source
Picture1.ScaleMode = vbPixels
Picture1.AutoRedraw = True
Picture1.AutoSize = True
Picture1.Visible = False
Set Picture1.Picture = LoadPicture("My_Image.bmp")
' destination
Picture2.ScaleMode = vbPixels
Picture2.AutoRedraw = True
Picture2.Move 0, 0, Picture1.Width, Picture1.Height
End Sub
Thank you! It worked!