'添加一个按钮,模拟小车,并命名:Command1
'小车速度
Dim 速度 As Integer
'速度上限
Dim 上限 As Integer
'加孝腔速状态(True减速False加速)
Dim 状态 As Boolean
Private Sub Form_Load()
速度 = 1
上限 = 100
'设置匀速时间(毫秒:1秒=1000毫秒)
Timer2.Interval = 2000
'设置运动控制时钟为30毫秒(即FPS:空慎昌60)
Timer1.Interval = 30
End Sub
Private Sub Timer1_Timer()
Command1.Left = Command1.Left + 速度
If 状态 Then
If 速斗扒度 > 1 Then 速度 = 速度 - 1
Else
If 速度 <= 上限 Then
速度 = 速度 + 1
Else
If Timer2.Enabled = False Then Timer2.Enabled = True
End If
End If
End Sub
Private Sub Timer2_Timer()
状态 = True
End Sub
创建一个高唯Timer控件,脊念桐取名Timer1,然后加入以下代码
Private Sub Form_Load()Timer1.Interval = 10 '设置小车每10毫秒移动一次
End Sub
Private Sub Timer1_Timer()
小车.Left = 小车.Left + 50 '小车每次移动都往右移50缇
End Sub
启动程序,就可樱坦以了
如果不懂,可以追问
Const pi As Single = 3.141593Dim l As Single
Private Sub Form_Load()
l = Me.ScaleHeight / Me.ScaleWidth
Me.Scale (-100, 100 * l)-(100, -100 * l)
Me.AutoRedraw = True
Shape1.Shape = 3
Shape1.BorderStyle = 0
Shape1.FillStyle = 兆型0
Shape1.FillColor = vbRed
Shape1.Width = 10
Me.Circle (0, 0), 50, vbBlue
Timer1.Interval = 100
Timer1.Enabled = True
End 轮猜游Sub
Private Sub Timer1_Timer()
Dim x As Single, y As Single
Static s As Single
x = Cos(s * pi / 180) * 50
y = Sin(s * pi / 180) * 50
Shape1.Move x - 5, y + 5 * l
s = (s + 5) Mod 360
End Sub
以上代码用到腊销两个控件,Shape1和Timer1,均取默认值即可
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)