-
Im having some trouble with bitblt. I got it to move the paddle smoothly, but, it leaves a trail of itself behind it. any suggestions? heres the code i used. I suspect I change the dwrop but I have no idea to what.
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
BitBlt Form1.hDC, X, Y, 51, 14, picpaddle.hDC, 0, 0, SRCCOPY
End Sub
thanks
-
If you only blit once then you're not going to remove the old picture. If I've understood right, and you're blitting a small picture onto a background then you need to either refresh the whole background before you blit again, or just refresh the area you last painted to. If you see what I mean.
-
For smoothness, compile an image of the whole changed area in its new state, then blit that rather than the new paddle image. This way you won't get horrible flicker.
-
I see what you mean, i works fine now. Thanks
-
It will even work MORE fine if you Blt the background to a memory DC!
-
yes it will look a heck of a lot better if you do as parksie says and paint the whole image to a back buffer (invisible) first, then blit that compiled image to the front buffer (the bit you see). You can do this with an invisible picture box (or is it image box - I can't remember now), or as Mad Compie says use a memory DC for the back buffer. Using a memory DC saves on resources.
Typically for this you would have 3 calls to BitBlt in a row (4 if you use a mask):
Blit background to back buffer
(Blit foreground mask to back buffer)
Blit foreground (small image) to back buffer
Blit back buffer to front buffer
-
I don't really understand what your saying. Do you mean have a picture box that is the same as the backround and blit that everytime I move the padde unstead of using form1.refresh?
-
To make life easier, I will sort out an example project with full comments...I will then post it here.
-
im still new to this all but I know something is not right in the last line. Can anyone help me out
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
-BitBlt Form1.hDC, X, Y, 51, 14, picpaddle.hDC, 0, 0, SRCCOPY
-buffer = BitBlt(Form1.hDC, 0, 0, Form1.Width, Form1.Height, Form1.hDC, 0, 0, SRCCOPY)
-BitBlt Form1.hDC, 0, 0, 0, 0, buffer?, 0, 0, SRCCOPY
End Sub
it also leaves a trail of the paddle when you move it. I've tried many things but to no success..
-
I'll put this in my example, which will probably be finished by tomorrow morning (that is, in about 14 hours time).
-
-
Here it is: http://www.parksie.uklinux.net/bitblt.zip
It demonstrates: Memory DCs + bitmaps. It basically demonstrates how to double-buffer.
-
Controls:
tmrGame - Timer: INTERVAL(100)
picBack - PictureBox: VISIBLE(FALSE),AUTOREDRAW(TRUE)
picBlt - PictureBox
picPaddle - PictureBox: VISIBLE(FALSE),AUTOREDRAW(TRUE)
PaddleX - X~Pos of Paddle
PaddleY - Y~Pos of Paddle
Code:
Private Sub TmrGame_Timer()
Dim RC
picBack.CLS
RC = BitBlt(picBack.hDC,PaddleX,PaddleY,picPaddle.ScaleWidth,picPaddle.ScaleHeight,picPaddle.hDC,0,0,SRCCOPY)
CopyBlt PicBack.hDC, PicBlt.hDC
End Sub
Sub CopyBlt(hSrcDC As Long,hDstDC As Long,W As Integer,H As Integer)
Dim Ret
Ret = Bitblt(hDstDC,0,0,W,H,hSrcDC,0,0,SRCCOPY)
End Sub
I believe that will work.
-
Thanks everyone! I have a much better understanding now. The code examples were great