在图片框移动时,如何使我的精灵动画?它还需要每次通过一个角落的位置

发布于 2025-01-22 11:23:31 字数 2739 浏览 0 评论 0原文

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

Pls help I want it to go like
enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以笙箫默 2025-01-29 11:23:31

您可以尝试交换图像框的高度和宽度,然后在内部旋转图像以达到所需的效果。

    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 + 2
    animate()
    If R1.Left >= 219 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 + 2
    animate()
    R1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)
    R1.Refresh()
    If R1.Top >= 202 Then
        Dim w = R1.Width
        R1.Width = R1.Height
        R1.Height = w
        Timer2.Stop()
        Timer3.Start()
    End If
End Sub

Private Sub animate()
    If anm = 1 Then
        R1.Image = Image.FromFile("picture1")
        anm = 2
    ElseIf anm = 2 Then
        R1.Image = Image.FromFile("picture2")
        anm = 3
    ElseIf anm = 3 Then
        R1.Image = Image.FromFile("picture3")
        anm = 4
    ElseIf anm = 4 Then
        R1.Image = Image.FromFile("picture4")
        anm = 1
    End If
End Sub

You can try swapping the height and width of the picturebox and then rotating the image inside to achieve the effect you want.

    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 + 2
    animate()
    If R1.Left >= 219 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 + 2
    animate()
    R1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)
    R1.Refresh()
    If R1.Top >= 202 Then
        Dim w = R1.Width
        R1.Width = R1.Height
        R1.Height = w
        Timer2.Stop()
        Timer3.Start()
    End If
End Sub

Private Sub animate()
    If anm = 1 Then
        R1.Image = Image.FromFile("picture1")
        anm = 2
    ElseIf anm = 2 Then
        R1.Image = Image.FromFile("picture2")
        anm = 3
    ElseIf anm = 3 Then
        R1.Image = Image.FromFile("picture3")
        anm = 4
    ElseIf anm = 4 Then
        R1.Image = Image.FromFile("picture4")
        anm = 1
    End If
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文