在图片框移动时,如何使我的精灵动画?它还需要每次通过一个角落的位置
Public Class Form1
Dim anm As Integer = 1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
R1.Left = R1.Left + 5
animate()
If R1.Left >= 210 Then
Dim w = R1.Width
R1.Width = R1.Height
R1.Height = w
Timer1.Stop()
Timer2.Start()
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
R1.Top = R1.Top + 5
animate()
R1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)
R1.Refresh()
If R1.Top >= 190 Then
Dim w = R1.Width
R1.Width = R1.Height
R1.Height = w
Timer2.Stop()
Timer3.Start()
End If
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
R1.Left = R1.Left - 5
animate()
R1.Image.RotateFlip(RotateFlipType.Rotate180FlipNone)
R1.Refresh()
If R1.Top <= 0 Then
Dim w = R1.Width
R1.Width = R1.Height
R1.Height = w
Timer3.Stop()
Timer4.Start()
End If
End Sub
Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
R1.Top = R1.Top - 2
animate()
R1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)
R1.Refresh()
If R1.Top <= 0 Then
Dim w = R1.Width
R1.Width = R1.Height
R1.Height = w
Timer4.Stop()
Timer1.Start()
End If
End Sub
Private Sub animate()
If anm = 1 Then
R1.Image = Image.FromFile(Application.StartupPath & "\1_SONICRUN1-removebg-preview-removebg-preview.png")
anm = 2
ElseIf anm = 2 Then
R1.Image = Image.FromFile(Application.StartupPath & "\1_SONICRUN2-removebg-preview-removebg-preview.png")
anm = 3
ElseIf anm = 3 Then
R1.Image = Image.FromFile(Application.StartupPath & "\1_SONICRUN3-removebg-preview-removebg-preview.png")
anm = 4
ElseIf anm = 4 Then
R1.Image = Image.FromFile(Application.StartupPath & "\1_SONICRUN4-removebg-preview-removebg-preview.png")
anm = 1
End If
End Sub
End Class
每次撞到拐角处,它一开始就朝向颠倒,并且当它撞到角落时,它都需要切换位置。确保可以的好,请帮助我真的需要帮助。谢谢大家。我需要它在图片框中移动时动画。
Public Class Form1
Dim anm As Integer = 1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
R1.Left = R1.Left + 5
animate()
If R1.Left >= 210 Then
Dim w = R1.Width
R1.Width = R1.Height
R1.Height = w
Timer1.Stop()
Timer2.Start()
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
R1.Top = R1.Top + 5
animate()
R1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)
R1.Refresh()
If R1.Top >= 190 Then
Dim w = R1.Width
R1.Width = R1.Height
R1.Height = w
Timer2.Stop()
Timer3.Start()
End If
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
R1.Left = R1.Left - 5
animate()
R1.Image.RotateFlip(RotateFlipType.Rotate180FlipNone)
R1.Refresh()
If R1.Top <= 0 Then
Dim w = R1.Width
R1.Width = R1.Height
R1.Height = w
Timer3.Stop()
Timer4.Start()
End If
End Sub
Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
R1.Top = R1.Top - 2
animate()
R1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)
R1.Refresh()
If R1.Top <= 0 Then
Dim w = R1.Width
R1.Width = R1.Height
R1.Height = w
Timer4.Stop()
Timer1.Start()
End If
End Sub
Private Sub animate()
If anm = 1 Then
R1.Image = Image.FromFile(Application.StartupPath & "\1_SONICRUN1-removebg-preview-removebg-preview.png")
anm = 2
ElseIf anm = 2 Then
R1.Image = Image.FromFile(Application.StartupPath & "\1_SONICRUN2-removebg-preview-removebg-preview.png")
anm = 3
ElseIf anm = 3 Then
R1.Image = Image.FromFile(Application.StartupPath & "\1_SONICRUN3-removebg-preview-removebg-preview.png")
anm = 4
ElseIf anm = 4 Then
R1.Image = Image.FromFile(Application.StartupPath & "\1_SONICRUN4-removebg-preview-removebg-preview.png")
anm = 1
End If
End Sub
End Class
It needs to switch position every time it hits a corners like it faces upside down at first and when it hits the corner it faces downwards. Make sure its ok pls can you please help I really need the help. Thanks guys. I need it to animate while the picture box is moving in a loop.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试交换图像框的高度和宽度,然后在内部旋转图像以达到所需的效果。
You can try swapping the height and width of the picturebox and then rotating the image inside to achieve the effect you want.