School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,363 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,442 people online right now. Registration is fast and FREE... Join Now!




Animation: Moving an image

 
Reply to this topicStart new topic

> Animation: Moving an image, across the screen

firebolt
Group Icon



post 11 Apr, 2009 - 01:21 AM
Post #1


Hi.

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.
CODE

Dim pos As Integer


Then we code the Move button.
CODE

Private Sub cmdMove_Click()
pos = 100
If cmdMove.Caption = "start" Then
cmdMove.Caption = "stop"
tmrSpeed.Enabled = True
Else
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.
CODE

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.
CODE

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.
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/7/09 08:37PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month