本例欲通过move方法完成一只蝴蝶的飞翔过程。通过定时器的中断,每隔一定时间(本例为0.2秒),在屏幕上移动蝴蝶的位置,并且改变蝴蝶的形态(展翅和收翅),于是利用视觉的暂存效应,看到蝴蝶栩栩如生的飞行场面。蝴蝶的位置的移动就由move方法来实现,move方法使用的格式如下:
对象. move left, top
其中left为对象左边界的水平坐标(x轴),top为对象上边界的垂直坐标(Y轴),本例中的对象框(image box),名字为main。
蝴蝶的展翅和收翅图象由位图文件bfly1.bmp bfly2.bmp来提供,并可根据需要制作其它飞行的位图文件,以使效果更加逼真。
本例中窗体结构和各个对象的属性设置如下:
对象 属性设置
窗体caption 蝴蝶飞行动画设计
图象框name main
picture bfly1
图象框name openwings
picture bfly1
图象框name closewings
picture bfly2
命令框name command1
caption E&xit
定时器name timer1
interval 200
有关程序比较简单,代码如下:
定时器中断程序:
Private SubTimer-Timer()
Static PickBmp As Integer
Main.Move Main.Left 20,Main.Top -5
If PickBmp Then
Main.Picture =Open Wings.Picture'Displays the open butterfly picture.
Else
Main.Picture =Close Wings.Picture'Displays the closed butterfly picture.
End If
PickBmp=Not PickBmp'Toggle the value.
End Sub
退出按钮(exit)程序:
Private Sub Command1-Click()
Unload Me
End
End Sub
这样,利用VB的move方法和其它对象属性,就可以实现更加复杂的动画设计。
上一篇: Visual Basic 中制作流水灯
下一篇: 用CallByName函数实现字符动画
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




