用VB设计一个动画,小球的弹跳运动,小球的滚动
1个回答
展开全部
我有窗口的弹跳完整代码,可自行根据需要修改,有用请采纳,谢谢
'以下代码自动添加timer和调整form大小,仅供参考
'添加一个模块,写入
'=======================
Option Explicit
Type POINTAPI
X As Long
Y As Long
End Type
Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
'=======================
'以下代码写入form中
'===========================
Option Explicit
Dim Vt, V0, t As Single
Dim CurXY As POINTAPI ' 声明变量
Dim X0, Y0, X1, Y1, MX, MY, N As Single
Dim meclick As Boolean
Private WithEvents Timer1 As Timer
Private WithEvents Timer2 As Timer
Private Sub Form_Load()
Me.BorderStyle = 1
Me.Width = 2000
Me.Height = 2000
Set Timer1 = Controls.Add("vb.timer", "timer1")
Timer1.Interval = 10
Set Timer2 = Controls.Add("vb.timer", "timer2")
Timer2.Enabled = False
Timer2.Interval = 10
End Sub
Sub ks()
V0 = 0
Vt = 0
t = 0
Timer1.Enabled = True
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ks
Timer1.Enabled = False
Timer2.Enabled = True
meclick = True
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
meclick = False
Dim NewForm As Form
Set NewForm = Form1
Form1.Show
End Sub
Private Sub Timer1_Timer()
Dim a As Integer
a = 10
If Me.Top + Me.Height > Screen.Height Then
V0 = Int(Vt * 0.9)
Me.Top = Screen.Height - Me.Height
If Abs(V0) < 0.9 Then
Timer1.Enabled = False
End If
t = 0
End If
t = t + 1
Vt = a * t - V0
Me.Top = Me.Top + Vt
If Me.Left < 0 Then Me.Left = 0
If Me.Left > Screen.Width - Me.Width Then Me.Left = Screen.Width - Me.Width
End Sub
Private Sub Timer2_Timer()
N = 0.09
X0 = Me.Left + Me.Width / 2
Y0 = Me.Top + Me.Height / 2
If meclick = True Then
GetCursorPos CurXY
X1 = CurXY.X * 15
Y1 = CurXY.Y * 15
End If
MX = (X1 - X0) * N
MY = (Y1 - Y0) * N
If Abs(MX) < 5 And Abs(MY) < 5 And meclick = False Then
Timer2.Enabled = False
ks
End If
Me.Left = Me.Left + MX
Me.Top = Me.Top + MY
End Sub
'以下代码自动添加timer和调整form大小,仅供参考
'添加一个模块,写入
'=======================
Option Explicit
Type POINTAPI
X As Long
Y As Long
End Type
Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
'=======================
'以下代码写入form中
'===========================
Option Explicit
Dim Vt, V0, t As Single
Dim CurXY As POINTAPI ' 声明变量
Dim X0, Y0, X1, Y1, MX, MY, N As Single
Dim meclick As Boolean
Private WithEvents Timer1 As Timer
Private WithEvents Timer2 As Timer
Private Sub Form_Load()
Me.BorderStyle = 1
Me.Width = 2000
Me.Height = 2000
Set Timer1 = Controls.Add("vb.timer", "timer1")
Timer1.Interval = 10
Set Timer2 = Controls.Add("vb.timer", "timer2")
Timer2.Enabled = False
Timer2.Interval = 10
End Sub
Sub ks()
V0 = 0
Vt = 0
t = 0
Timer1.Enabled = True
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ks
Timer1.Enabled = False
Timer2.Enabled = True
meclick = True
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
meclick = False
Dim NewForm As Form
Set NewForm = Form1
Form1.Show
End Sub
Private Sub Timer1_Timer()
Dim a As Integer
a = 10
If Me.Top + Me.Height > Screen.Height Then
V0 = Int(Vt * 0.9)
Me.Top = Screen.Height - Me.Height
If Abs(V0) < 0.9 Then
Timer1.Enabled = False
End If
t = 0
End If
t = t + 1
Vt = a * t - V0
Me.Top = Me.Top + Vt
If Me.Left < 0 Then Me.Left = 0
If Me.Left > Screen.Width - Me.Width Then Me.Left = Screen.Width - Me.Width
End Sub
Private Sub Timer2_Timer()
N = 0.09
X0 = Me.Left + Me.Width / 2
Y0 = Me.Top + Me.Height / 2
If meclick = True Then
GetCursorPos CurXY
X1 = CurXY.X * 15
Y1 = CurXY.Y * 15
End If
MX = (X1 - X0) * N
MY = (Y1 - Y0) * N
If Abs(MX) < 5 And Abs(MY) < 5 And meclick = False Then
Timer2.Enabled = False
ks
End If
Me.Left = Me.Left + MX
Me.Top = Me.Top + MY
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询