VB的动画实现原理
?牐犘陆ㄒ桓龉こ蹋诖疤迳咸砑恿礁鯰imer控件,三个Image控件,然后在代码窗口中添加以下代码:
?牐燚im i As Integer
?牐燚im j As Integer
?牐燚im k As Integer
?牐燚im l As Integer
?牐燩rivate Sub Form_Load?煟?
?牐牐?让Image1和Image2重叠
?牐營mage2.Left = Image1.Left
?牐營mage2.Top = Image1.Top
?牐牐Т舜Φ耐计肪段喽月肪?
?牐營mage1.Picture = LoadPicture(“C:\Program Files\Tencent\newface\57-1.bmp”)
?牐營mage2.Picture = LoadPicture(“C:\Program Files\Tencent\newface\57-3.bmp”)
?牐營mage3.Picture = LoadPicture(“C:\Program Files\Tencent\newface\1-1.bmp”)
?牐牐?设置Timer1的时间间隔,并在Form1的Load事件中激活
?牐燭imer1.Interval = 10
?牐燭imer1.Enabled = True
?牐牐?设置Timer2的时间间隔,并在Form1的Load事件中激活
?牐燭imer2.Interval = 1000
?牐燭imer2.Enabled = True
?牐燛nd Sub
?牐燩rivate Sub Timer1_Timer()
?牐牐Ф蹋计穆肪段喽月肪?
?牐燬elect Case i
?牐燙ase 0
?牐燜orm1.Icon = LoadPicture(“C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Elements\moon01.ICO”)
?牐燙ase 1
?牐燜orm1.Icon = LoadPicture(“C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Elements\moon02.ICO”)
?牐燙ase 2
?牐燜orm1.Icon = LoadPicture(“C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Elements\moon03.ICO”)
?牐燙ase 3
?牐燜orm1.Icon = LoadPicture(“C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Elements\moon04.ICO”)
?牐燙ase 4
?牐燜orm1.Icon = LoadPicture(“C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Elements\moon05.ICO”)
?牐燙ase 5
?牐燜orm1.Icon = LoadPicture(“C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Elements\moon06.ICO”)
?牐燙ase 6
?牐燜orm1.Icon = LoadPicture(“C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Elements\moon07.ICO”)
?牐燙ase 7
?牐燜orm1.Icon = LoadPicture(“C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Elements\moon08.ICO”)
?牐燛nd Select
?牐牐Ц谋湟拍诘淖址栽诒晏饫赶允静煌谋晏?
?牐燜orm1.Caption = Left(“Wolf”, j)
?牐營mage3.Left = 240 + l
?牐爄 = i + 1
?牐爅 = j + 1
?牐爈 = l + 1
?牐牐?If 语句用来控制变量i和j的最大值
?牐營f i = 7 Then i = 0
?牐營f j = 5 Then j = 0
?牐燛nd Sub
?牐燩rivate Sub Timer2_Timer?煟?
?牐牐в肐f 语句来控制图像框的Visible的属性以达到动画效果
?牐營f k = 0 Then
?牐營mage1.Visible = False
?牐營mage2.Visible = True
?牐燛lse
?牐營mage1.Visible = True
?牐營mage2.Visible = False
?牐燛nd If
?牐爇 = k + 1
?牐牐?If语句用来控制变量k的最大值
?牐營f k = 2 Then k = 0
?牐燛nd Sub
?牐犚陨系耐计谀愕挠才汤锒寄苷业剑比唬阋部梢杂媚阆不兜耐计刺婊凰恰?
?牐犗衷诎碏5运行,是不是动起来了啊?窗体上的图标在动,标题也在动,小企鹅从左到右移动,还有一个卡通人物眼晴眨啊眨的,是不是很有趣啊?你可以修改Timer的Interval属性来控制动画的速度,其实这只是一些简单动画的演示实例,要做出更加漂亮的动画还需要大家努力喔。