Home > Mobile >  How do I make my sprite animate while the picture box is moving? It also needs to change position ev
How do I make my sprite animate while the picture box is moving? It also needs to change position ev

Time:05-10

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.

CodePudding user response:

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
  • Related