VB中的简单动画代码设计

               最近接触VB百例时接触到了简单的动画设计,现在将程序相关的知识整理在这里.(下面是一个例子--逃跑的小恐龙)

              首先,打开Visual Basic ,新建窗体,在窗体中添加计时器控件、image1控件数组(个数根据自己的程序而定)、image2(用于动画的播放)

             

                         Option Explicit

                          Private Sub Form_Load()
                               img2.Left = 0                    '使image从最左边开始
                          End Sub

 

                       Private Sub Timer1_Timer()
                          Static x As Integer
                            If x = 7 Then x = 1                            ‘7为一个循环期  
                              x = x + 1
                              img2.Move img2.Left + 100
                          If img2.Left > Me.Width Then
                             img2.Left = 0
                          End If
                      Select Case x                                               'select case 语句实现了多个图片连接起来的动画
                        Case 1
                           img2.Picture = img1(0).Picture
                       Case 2
                          img2.Picture = img1(1).Picture
                      Case 3
                           img2.Picture = img1(2).Picture
                      Case 4
                            img2.Picture = img1(3).Picture
                      Case 5
                            img2.Picture = img1(4).Picture
                     Case 6
                            img2.Picture = img1(5).Picture
                      End Select
                 End Sub

 

你可能感兴趣的:(VB中的简单动画代码设计)