Results 1 to 3 of 3

Thread: BitBlt....Please Help!

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Location
    Worksop
    Posts
    4

    Post

    Not sure if it will help but if you try http://www.codearchive.com there's a vb project that use this technique - One entitled picanimate (I think) moves a spaceship sprite around a screen using a timer in response to a mouse click.

  2. #2
    New Member
    Join Date
    Jan 2000
    Posts
    11

    Post

    I'm making a hunting game in VB6, and I'm trying to figure out how to implement BitBlt into it.
    I have some sample source that I found from vb-world, but I need to figure out how to make it so that I can use a timer to move the mask/picsource to a new destination every second or so. Here's what I have for code, please somebody help:

    [Form1 code]
    Dim xdest As Long
    Dim ydest As Long

    Sub refreshscreen()
    Form1.Cls
    Call BitBlt(picbuf.hDC, 0, 0, 214, 161, picback.hDC, 0, 0, SRCCOPY)
    Call BitBlt(picbuf.hDC, xdest, ydest, 32, 32, picMask.hDC, 0, 0, SRCAND)
    Call BitBlt(picbuf.hDC, xdest, ydest, 32, 32, picsource.hDC, 0, 0, SRCINVERT)
    Call BitBlt(Form1.hDC, 0, 0, 214, 161, picbuf.hDC, 0, 0, SRCCOPY)
    End Sub


    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode

    Case vbKeyRight
    xdest = xdest + 5
    refreshscreen

    Case vbKeyLeft
    xdest = xdest - 5
    refreshscreen

    Case vbKeyUp
    ydest = ydest - 5
    refreshscreen

    Case vbKeyDown
    ydest = ydest + 5
    refreshscreen

    End Select

    If xdest < 10 Then xdest = 10
    If xdest > 170 Then xdest = 170
    If ydest < 10 Then ydest = 10
    If ydest > 120 Then ydest = 120

    End Sub

    Private Sub Form_Load()
    Dim leftd, topd
    leftd = Int(Rnd * picback.Width)
    topd = Int(Rnd * picback.Height)
    xdest = 100
    ydest = 100
    refreshscreen
    End Sub

    Private Sub picsource_Click()

    End Sub

    Private Sub Timer1_Timer()
    picbuf.Left = leftd
    picsource.Left = picbuf.Left
    picbuf.Top = topd
    picsource.Top = picbuf.Top
    End Sub


    [Module code]
    Public 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

    Global Const White = 16777215
    Global Const SRCAND = &H8800C6
    Global Const SRCCOPY = &HCC0020
    Global Const SRCINVERT = &H660046
    Global Const srcpaint = vbSrcPaint


    What am I doing wrong? I'm trying to move the picture to a new spot every second, and it doesn't move. (I also have the keyboard input, where it moves using the arrow keys, but how do I get it to work like I want it to?)

    Thanks for any help I get.
    -BLiNDPiG

  3. #3
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    Post

    Hi there again!

    I read the code and saw somehting you made not the best way . First you don't have to declare the consts (drawing method). You can directly use vbSrcCopy, vbSrcPaint, ...

    Next is that you don't have to move the buffer coz you're drawing the whole picture *out* the buffer, so it doesn't matter where it is.

    Last is how you're blitting it, try this:

    -
    BitBlt( Buffer.hdc, 0, 0, BackW, BackH, Back.hdc, 0, 0, vbSrcCopy )
    BitBlt( Buffer.hdc, 0, 0, PicW / 2, PicH, Back.hdc, PicW / 2, 0, vbSrcPaint )
    BitBlt( Buffer.hdc, 0, 0, PicW / 2, PicH, Back.hdc, 0, 0, vbSrcAnd )
    BitBlt( Front.hdc, 0, 0, FrontW, FrontH, Buffer.hdc, 0, 0 vbSrcCopy )
    -

    Note that your Picture must have a same-sized mask on the right side (Original pic: White background, Mask picture: White object on black background)

    Good luck!

    ------------------
    [email protected]
    ...
    Every program can be reduced to one instruction which doesn't work.



    [This message has been edited by Fox (edited 01-26-2000).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width