Page 1 of 1

Animation: Moving an image across the screen Rate Topic: -----

#1 firebolt   User is offline

  • D.I.C Lover
  • member icon

Reputation: 93
  • View blog
  • Posts: 5,561
  • Joined: 20-February 09

Posted 11 April 2009 - 02:21 AM


This tutorial isone of many methods which allow objects such as images to move across the screen otherwise animate. We start off with creating an image in any program and saving it as a .bmp file. This is the only file format in which VB6 may allow objects to move in a form. Then we will create a background for our form which may be saved as a .jpg format. Then we start making our form.

First we need to name our form, Form1 . Next we create a button called Move naming it cmdMove . After, we create a timer, tmrSpeed and an image naming it imgPic . Now we can start our coding...

We first declare pos above all subs so this can be used in all subs.
Dim pos As Integer

Then we code the Move button.
Private Sub cmdMove_Click()
pos = 100
If cmdMove.Caption = "start" Then
cmdMove.Caption = "stop"
tmrSpeed.Enabled = True
cmdMove.Caption = "start"
tmrSpeed.Enabled = False
End If
End Sub

This part (above) uses the timer and tells the form when the form starts, the timer is disabled. It also tells the form when to start the form and when to stop it.

This section goes under the form when it loads. We load the background that you have made. It also tells us the timer interval which is 50.
Private Sub Form_Load()
Form1.Picture = LoadPicture("C:\Background.jpg")
tmrSpeed.Interval = 50
tmrSpeed.Enabled = False
imgPic.Top = 3665
End Sub

Now all that's left is to code the timer, tmrSpeed.
Private Sub tmrSpeed_Timer()
imgPic.Left = pos
imgPic.Picture = LoadPicture("C:\Pic.bmp")
pos = pos + 30
End Sub

The timer tells the form which way the image moves. It also loads the image and positions it within the form.

Now all we need to do is to load the form and click on the button to move the image.
Thank you.

PS: Please check for any errors which need to be addressed.

Is This A Good Question/Topic? 1
  • +

Page 1 of 1