Results 1 to 3 of 3

Thread: BitBlt - not for the faint-hearted...

  1. #1

    Thread Starter
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205

    Unhappy BitBlt - not for the faint-hearted...

    Hi all, I am making a drawing prog which will place tiles in a square in a nxn grid of 32x32 squares.

    The user simply drags a tile to where they want it and Voila!

    However, so the user can see where their tile is gonna go (without drawing gridlines on the picture), I want an outline box to position itself where a tile would go as the user drags said tile around the picture.

    I am using BitBlt to draw the tiles.

    The following sub is called as the user drags a tile around the picture:

    ********************

    Private Sub pictureFront_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
    X = (X - (X Mod 32))
    Y = (Y - (Y Mod 32))

    If ((X = lastX) And (Y = lastY)) Then Exit Sub

    lastX = X
    lastY = Y


    'Draw the outline
    BitBlt pictureDragOutlineBuffer.hDC, X, Y, dragOutlineBox.Width / 2, dragOutlineBox.Height, dragOutlineBox.hDC, dragOutlineBox.Width / 2, 0, vbSrcPaint 'The mask, important for transparency
    BitBlt pictureDragOutlineBuffer.hDC, X, Y, dragOutlineBox.Width / 2, dragOutlineBox.Height, dragOutlineBox.hDC, 0, 0, vbSrcAnd 'The player himself

    'Flip (Copy the buffer to the screen)
    #1: BitBlt FrontDC, 0, 0, pictureFront.Width, pictureFront.Height, pictureDragOutlineBuffer.hDC, 0, 0, vbSrcCopy
    #2: BitBlt FrontDC, 0, 0, pictureFront.Width, pictureFront.Height, BackDC, 0, 0, vbSrcCopy

    Dim A, B
    'Draw the background tiles
    For A = 0 To pictureFront.Width / Tile.Width
    For B = 0 To pictureFront.Height / Tile.Height
    BitBlt pictureDragOutlineBuffer.hDC, A * Tile.Width, B * Tile.Height, Tile.Width, Tile.Height, Tile.hDC, 0, 0, vbSrcCopy 'Just copy the memory so no mask
    Next
    Next
    End Sub

    ********************
    However, this doesn't work very well.The lines marked #1 & #2 have the following effect:
    #1: draws the pictureBox which has the outline in it onto the canvas
    #2: draws the pictureBox which has the actual picture onto the canvas.

    If I remove #1, I get no outline when dragging...
    If remove #2, the actual picture draws itself over the outline as I go...


    As you may have noticed, the outline and the actual picture are 'stored' in two different 'buffer' picture boxes...


    Any suggestions?
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  2. #2

    Thread Starter
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205

    Re: BitBlt - not for the faint-hearted...

    Originally posted by rjlohan
    If remove #2, the actual picture draws itself over the outline as I go...
    Or rather, if I remove #2, i can see the outline, but the picture only draws when I let go the mouse button. so this is no good, 'cause you can't see what you've already drawn...
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  3. #3
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Well, I'd do it like this:

    1) Have a function which redraws all the tiles
    2) In the MouseMove sub, call that sub and then draw the rectangle.

    That should do it (it's how I did my map maker)
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

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