Compared with structured programs, Visual Basic adds the "method" function of objects. Fully mastering this "method" that is different from object properties is extremely important for the development of visualization applications. Below, take the move method of VB4.0 as an example to illustrate the application of this method in animation.
In this example, we want to use the move method to complete the flight process of a butterfly. Through the interruption of the timer, at certain intervals (0.2 seconds in this example), the position of the butterfly is moved on the screen, and the shape of the butterfly is changed (wings spread and wings retracted), so that the temporary effect of vision is used to see the butterfly come to life. flight scene. The movement of the butterfly's position is realized by the move method. The format used by the move method is as follows:
Object.moveleft,top
Among them, left is the horizontal coordinate of the left boundary of the object (x-axis), and top is the vertical coordinate of the upper boundary of the object (Y-axis). In this example, the object box (imagebox) is named main.
The image of the butterfly's wings spread and folded is provided by the bitmap file bfly1.bmpbfly2.bmp, and other flying bitmap files can be produced as needed to make the effect more realistic.
In this example, the form structure and the properties of each object are set as follows:
Object property settings
Form caption butterfly flight animation design
image frame namemain
picturebfly1
imageframenameopenwings
picturebfly1
imageframenameclosewings
picturebfly2
command box namecommand1
captionE&xit
timernametimer1
interval200
The relevant program is relatively simple, the code is as follows:
Timer interrupt program:
PRivateSubTimer-Timer()
StaticPickBmpAsInteger
Main.MoveMain.Left 20,Main.Top-5
IfPickBmpThen
Main.Picture=OpenWings.Picture'Displaystheopenbutterflypicture.
Else
Main.Picture=CloseWings.Picture'Displaystheclosedbutterflypicture.
EndIf
PickBmp=NotPickBmp'Togglethevalue.
EndSub
Exit button (exit) program:
PrivateSubCommand1-Click()
UnloadMe
End
EndSub
In this way, using VB's move method and other object properties, you can achieve more complex animation design. ->