Lesson 31: Animation - Part Ii: 31.1 Animation Using A Dragdrop Procedure
Lesson 31: Animation - Part Ii: 31.1 Animation Using A Dragdrop Procedure
You can actually copy the above images and use them in your program. You need to put all the above images overlapping one another, make image1 visible while all other images invisible at start-up. Next, insert a command button and label it as Animate. Click on the command button and key in the statements that make the images appear and disappear successively by using the properties image.visible=true and image.visible=false. I use If..... Then and Elseif to control the program flow. When you run the program, you should be able to get the following animation
The Interface The Code Private Sub Command1_Click() If Image1.Visible = True Then Image1.Visible = False Image2.Visible = True ElseIf Image2.Visible = True Then Image2.Visible = False Image3.Visible = True ElseIf Image3.Visible = True Then Image3.Visible = False Image4.Visible = True ElseIf Image4.Visible = True Then Image4.Visible = False Image5.Visible = True ElseIf Image5.Visible = True Then Image5.Visible = False Image6.Visible = True ElseIf Image6.Visible = True Then Image6.Visible = False
Image7.Visible = True ElseIf Image7.Visible = True Then Image7.Visible = False Image8.Visible = True ElseIf Image8.Visible = True Then Image8.Visible = False Image1.Visible = True End If End Sub If you wish to create the effect of the butterfly flapping its wing and flying at the same time, then you could use the Left and Top properties of an object, such as the one used in the examples of lesson 23. Below is an example of a subroutine where the butterfly will flap its wing and move up at the same time. You can also write subroutines that move the butterfly to the left, to the right and to the bottom. Sub move_up( ) If Image1.Visible = True Then Image1.Visible = False Image2.Visible = True Image2.Top = Image2.Top - 100 ElseIf Image2.Visible = True Then Image2.Visible = False Image3.Visible = True Image3.Top = Image3.Top - 100 ElseIf Image3.Visible = True Then Image3.Visible = False Image4.Visible = True Image4.Top = Image4.Top - 100 ElseIf Image4.Visible = True Then Image4.Visible = False Image5.Visible = True Image5.Top = Image5.Top - 100 ElseIf Image5.Visible = True Then Image5.Visible = False Image6.Visible = True Image6.Top = Image6.Top - 100
ElseIf Image6.Visible = True Then Image6.Visible = False Image7.Visible = True Image7.Top = Image7.Top - 100 ElseIf Image7.Visible = True Then Image7.Visible = False Image8.Visible = True Image8.Top = Image8.Top - 100 ElseIf Image8.Visible = True Then Image8.Visible = False Image1.Visible = True Image1.Top = Image1.Top - 100 End If End Sub