Results 1 to 7 of 7

Thread: making objects move with BitBlt

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2002
    Location
    UK
    Posts
    38

    Question making objects move with BitBlt

    i've just learnt the basics of BitBlt but can't get anything to move.

    say when a timer goes off you move a picture to the right a bit so it looks as if it's going along. what would the code be?

    this should be the last of my BitBlt posts if it gets any answers that work

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    In an interval (ex. a Do... DoEvents... Loop or Timer), you can just change the X/Y values (and even the thing you are "blitting") to your BitBlt call. This way simple animation and moving (walking animations too ) can be achieved.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    And don't forget that you have to refresh the form you're blitting to to see any movement...
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2002
    Location
    UK
    Posts
    38
    thanks
    this is part of my code:
    VB Code:
    1. Private Sub Timer1_Timer()
    2. intChange = intChange + 10
    3. BitBlt Picture2.hDC, intChange, 0, 1215, 1455, Picture1.hDC, 0, 0, SRCCOPY
    4. Me.Refresh
    5. End Sub
    it loads a new pic in the picture2 every time
    should a new one load every time and if yes how do i get rid of the old ones?

  5. #5
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    Try it this way:
    Code:
    retval = BitBlt(DestPicture.hDC, DestPictureUpperLeft,DestPictureX,DestPictureY, DestPictureWidth, DestPictureHeight, SourcePicture.hDC, SourcePictureLeftCorner,SourcePictureTopCorner, SRCCOPY)
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  6. #6
    Megatron
    Guest
    Well basically, you need to store your X and Y coordinates in variables, and anytime you want to move the image, you just change the X and Y coordinates.

    In the example above, if I wanted to move the picture to the right by 10 pixels I would use:
    Code:
    DestPictureX=DestPictureX+10
    DestPictureY=DestPictureY+10
    Then I'd call the function again, so it will redraw the picture in the new location.
    Code:
    retval = BitBlt(DestPicture.hDC, DestPictureUpperLeft,DestPictureX,DestPictureY, DestPictureWidth, DestPictureHeight, SourcePicture.hDC, SourcePictureLeftCorner,SourcePictureTopCorner, SRCCOPY)

  7. #7
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    To remove the old picture, use the .Cls method of the picturebox.

    To get rid of the flickering that comes from this method, search the board for double buffering, or put the picbox on AutoRedraw and use .Refresh after your BitBlt call(s).
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

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