How to Make Animations in Visual Basic 6.0

How to Make Animations in Visual Basic 6.0 thumbnail
Make Animations in Visual Basic 6.0

VB 6.0 is one of the most used development languages for developers. VB is often used to create graphical user interface applications and enable access to databases. Furthermore, you can create animations with VB 6.0 because controls have X and Y positions, which can be altered to create movements at run time.

Things You'll Need

  • Two dog images
Show More

Instructions

    • 1

      Go to "Start," then "All Programs." Click "Visual Basic 6.0." Click on "File," then "New" and select "Windows Application" in the New Project dialog. Click on "Image Control" and place it on your form. Right-click on the project, select "Properties" and click on the "Resources" tab. In the Resource Manager, add two dog images. The dog images need to be in the same directory as the project is. In the two images, the dog is either facing left or facing right.

    • 2

      Double-click the form background to bring up the Form_load event handler. Assign the dog image that is facing left to the image control. The dog can walk along the form from left to right or in the opposite direction. Thus there are four states for the dog: facing left or right and walking left or right. Enter the following enumeration code to define the dog's four states:

      Enum DogState

      FacingLeftWalkingLeft= 1

      FacingLeftWalkingRight = 2

      FacingRightWalkingRight = 3

      FacingRightWalkingLeft = 4

      End Enum

    • 3

      Add a timer to change the dog's movement by clicking on the "Clock" icon on the General sidebar. Set the timer to trigger a tick every 100 milliseconds. Set the initial state as FacingLeftWalkingLeft and speed as 10 pixels per tick, using the following code:

      state = DogState.FacingLeftWalkingLeft

      speed = 10

      DogImg.Image = My.Resources.Dog

    • 4

      Move the image control to the left using the fixed speed, and change the image. Check the location of the image control when it moves to the left or right. Make sure the image doesn't walk off the form. Flip the images when it reaches the left or right edges. You can achieve this by using the following Case and If-Else clause:

      Select Case state

      Case DogState.FacingLeftLeftLegs

      DogImg.Left = DogImg.Left - speed

      DogImg.Image = My.Resources.Dog2

      If DogImg.Left > 5 Then

      state = DogState.FacingLeftRightLegs

      Else

      state = DogState.FacingRightLeftLegs

      End If

Related Searches:

References

Resources

  • Photo Credit John Foxx/Stockbyte/Getty Images

Comments

You May Also Like

Related Ads

Featured