圖30.1: 設計界面
30.2 一個完整的動畫程式
到目前为止,在第29课动画的例子只涉及静态图片的移动。在这里,你将能够建立真正的动画程式。举例来说,一只扑动翅膀的蝴蝶。为了达到这个动画效果,我用了8个蝴蝶的画框。它显示蝴蝶处于不同扑动翅膀的阶段。
你其實可以下載上述圖象並用在它們在您的程式裡。你需要把上述所有的圖像重疊在一起,使Image1 在程式啟動時顯現而其他的圖像隱蔽。接下來,插入兩個命令按鈕,其中一個改標籤為啟動,另一個改標籤為停止。按一下啟動命令按鈕,並鍵入相關的陳述句。當程式運行時,您將看到以下的動畫:
.
圖30.2
程式碼
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
如果您想建立蝴蝶扑動翅膀和同一時間內飛行的效果,然后您可以使用Left 和 Top 的屬性,如下面的例子:
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