Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleAnimate a bouncing ball on a background
Keywordsbouncing ball, animation, background
CategoriesMultimedia, Graphics
 
Use BitBlt to erase the ball. Then draw the ball in its new location. When the ball gets too close to the edge of the picture, reverse the sign of its X or Y velocity.

The original version of this example used two PictureBoxes to hold the images. In this updated version, only one PictureBox holds the image initially. The program's Load event handler copies the image into the other PictureBox.

This saves space in the compiled executable, the .frx file, and thus the Zip file.

 
' Draw the ball at (CurX, CurY).
Private Sub DrawBall()
    ' Fix the part of the image that was covered.
    BitBlt picCanvas.hDC, _
        OldX - BallR, OldY - BallR, BallD, BallD, _
        picHidden.hDC, OldX - BallR, OldY - BallR, SRCCOPY
    OldX = CurX
    OldY = CurY

    ' Redraw the ball.
    picCanvas.Circle (CurX, CurY), BallR

    ' Update the display.
    picCanvas.Refresh
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated