Animation In Visual Basic - Part 1

Started by VelMurugan, Jul 16, 2008, 06:36 PM

Previous topic - Next topic

VelMurugan

Animation In VB

Animation is always an interesting and exciting part of programming. Although visual basic is not designed to handle advance animations, you can still create some interesting animated effects if you put  in some hard thinking. There are many ways to create animated effects in VB6, but for a start we will focus on some easy methods.

The simplest way to create animation is to set the VISIBLE property of a group of images or pictures or even texts and labels to true or false by triggering a set of events such as clicking a button. Let's examine the following example:

This is a program that create the illusion of moving the jet plane in four directions, North, South ,East, West. In order to do this, insert five images of the same picture into the form. Set the visible property of the image in the center to be true while the rest set to false. On start-up, a user will only be able to see the image in the center. Next, insert four command buttons into the form and change the labels to Move North, Move East, Move West and Move South respectively. Double click on the move north button and key in the following procedure:

                        Sub Command1_click( )
                        Image1.Visible = False
                        Image3.Visible = True
                        Image2.Visible = False
                        Image4.Visible = False
                        Image5.Visible = False
                       End Sub

By clicking on the move north button, image1 and other images except image 3 displayed. This will give an illusion that the jet plane has moved north. Key in similar procedures by double clicking other command buttons. You can also insert an addition command button and label it as Reset and key in the following codes:

                        Image1.Visible = True
                        Image3.Visible = False
                        Image2.Visible = False
                        Image4.Visible = False
                        Image5.Visible = False


Clicking on the reset button will make the image in the center visible again while other images become invisible, this will give the false impression that the jet plane has move back to the original position.

           

You can also issue the commands using a textbox, this idea actually came from my son Liew Xun (10 years old). His program is shown below:

        Private Sub Command1_Click()
        If Text1.Text = "n" Then
        Image1.Visible = False
        Image3.Visible = True
        Image2.Visible = False
        Image4.Visible = False
        Image5.Visible = False
        ElseIf Text1.Text = "e" Then
        Image1.Visible = False
        Image4.Visible = True
        Image2.Visible = False
        Image3.Visible = False
        Image5.Visible = False
        ElseIf Text1.Text = "w" Then
        Image1.Visible = False
        Image3.Visible = False
        Image2.Visible = False
        Image4.Visible = False
        Image5.Visible = True
        ElseIf Text1.Text = "s" Then
        Image1.Visible = False
        Image3.Visible = False
        Image2.Visible = True
        Image4.Visible = False
        Image5.Visible = False
        End If
        End Sub