This is a simple animation program where you can move the picture in any four directions by clicking on the buttons. In this program, you need to insert four timers and make them invisible and set the enabled property to false at start-up. Insert the move_up, move_down, move_left and move_right procedures into the respective timers as shown in the code. Use the move method and the computer coordinates system Left, Top to change the positions of the image. This program could be used to create various games later on. The basic syntax of the Move method is object.move Left, Top . For example, Image1.Move 1000,1000 will move the object Image1 to the location (1000,1000). I have also created four sub procedures Move_up, Move_down, Move_left and Move_right to move the image in the respective directions.
Dim x As Integer Dim y As Integer Dim v, w As Integer Static Sub move_right() v = v + 10 If v < 5350 Then Image1.Move v, w Else Image1.Move 2640, 1560 v = 2640 w = 1560 Timer1.Enabled = False End If End Sub Public Sub Command1_Click(Index As Integer) Timer2.Enabled = False Timer3.Enabled = False Timer4.Enabled = False Timer1.Enabled = True End Sub Private Sub move_down() w = w + 10 If w < 3670 Then Image1.Move v, w Else Image1.Move 2640, 1560 v = 2640 w = 1560 Timer2.Enabled = False End If End Sub
Private Sub move_left() v= v - 10 If v > 0 Then Image1.Move v,w Else Image1.Move 2640, 1560 v = 2640 w = 1560 Timer3.Enabled = False End If End Sub
Private Sub move_up() w = w - 10 If w > 0 Then
Image1.Move v, w Else Image1.Move 2640, 1560 v = 2640 w = 1560 Timer4.Enabled = False End If End
Private Sub Timer2_Timer() move_down End Sub Private Sub Timer3_Timer() move_left End Sub Private Sub Timer4_Timer() move_up End Sub
Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy