你好,欢迎访问远方教程PC版!
广告位招租
网站首页 >> 统计之窗 >> VB专区 >> 文章内容

VB应用举例07:在VB应用软件中实现动画效果(第4页)

[日期:2014-12-17]   来源:远方教程  作者:VBFans   阅读:6129次[字体: ] 访问[旧版]
 捐赠远方教程 

  四、使用Image实现动画效果

  该功能用定时器控件来控制移动和地球转动的速度,当然,其速度还与程序中设定的步长有关系,具体程序片段如下:

Private Sub Form_Load() 
  Timer_animate.inteval=100   ’INTEVAL属性为100ms 
  Timer_animate.enabled=true  ’启动动画定时器 
End Sub 

Private Sub Timer_animate_Timer() 
  Call ani_Image         ’定时调移动子程序 
End Sub 

Sub IncrFrame() 
  FrameNum = FrameNum + 1    ’帧加1 
  If FrameNum > 5 Then     ’最后一帧图像显示之后返回第一帧 
    FrameNum = 1 
    End If 
    Imageearth(0).Picture = Imageearth(FrameNum).Picture  
    ’将该帧图像赋给运动的Imageearth(0)控件的Picture属性 
End Sub 

Sub ani_Image()          ’控制移动子程序 
    Select Case Motion      ’控制移动方向的变量 
    Case 1             ’向上和向左移动,步长50 twips 
        Imageearth(0).Move Imageearth(0). 
        Left - 50, Imageearth(0).Top - 50 
        IncrFrame        ’切换到下一幅图 
        If Imageearth(0).Left < = 0 Then  ’向左移动到了边界 
            Motion = 2  向上和向右移动 
        ElseIf Imageearth(0).Top < = 0 Then 
            Motion = 4  向上移动到了边界,改向下和向左移动 
        End If 
    Case 2    向右和向上 
        Imageearth(0).Move Imageearth(0).Left + 50, 
        Imageearth(0).Top - 50 
            IncrFrame           ’到了右边界,转为向左和向上 
        If Imageearth(0).Left >= (startform.Width - Imageearth(0).Width) Then 
            Motion = 1 
        ElseIf Imageearth(0).Top < = 0 Then 
            Motion = 3   ’向右向下 
        End If 
    Case 3     ’向右向下 
      Imageearth(0).Move Imageearth(0).Left + 50, 
      Imageearth(0).Top + 50 
          IncrFrame 
       If Imageearth(0).Left >= (startform.Width - Imageearth(0).Width) Then 
            Motion = 4   ’向左向下 
       ElseIf Imageearth(0).Top >= (startform.Height - Imageearth(0).Height) - 680 Then 
            Motion = 2     ’向右向上,其中680 twips是标题和菜单的高度 
        End If 
    Case 4   ’向左向下 
      Imageearth(0).Move Imageearth(0).Left - 50,Imageearth(0).Top + 50 
      IncrFrame 
      If Imageearth(0).Left < = 0 Then   ’是否到了左边界,如到了转向右向下 
            Motion = 3    ’是否到了下边界 
      ElseIf Imageearth(0).Top >= (startform.Height - Imageearth(0).Height) - 680 Then 
            Motion = 1     ’向左向上 
      End If 
    End Select 
End Sub
图片展示
 
 
相关评论
站长推荐