'How to make the ball animate like its rolling And also the kicker how to animate the soccer player and how to sync them so it looks like he is kicking

THE PROGRAM HAS 3 FORMS FORM 1 CODE

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Form2.Show()
        Form2.Location = New Point(485, 100)
        Form2.Width = 400
        Form2.Height = 300

        Form3.Show()
        Form3.Location = New Point(860, 100)
        Form3.Width = 400
        Form3.Height = 300

        Me.Location = New Point(100, 100)
        Me.Width = 400
        Me.Height = 300

        Me.Location = New Point(100, 100)
        Me.Width = 400
        Me.Height = 300
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        OS1.Left = OS1.Left + 3
        Form2.OS2.Visible = False
        Form3.OS3.Visible = False
        If OS1.Left >= 350 Then
            Timer1.Stop()
            OS1.Visible = False
            Form2.OS2.Visible = True
            Form2.Timer1.Start()
        End If
    End Sub
End Class

FORM 2 CODE

Public Class Form2

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        OS2.Left = OS2.Left + 3
        If OS2.Left >= 350 Then
            Timer1.Stop()
            OS2.Visible = False
            Form3.OS3.Visible = True
            Form3.Timer1.Start()
        End If
    End Sub
End Class

FORM 3 CODE

Public Class Form3

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        OS3.Left = OS3.Left + 3
        If OS3.Left >= 200 Then
            Timer1.Stop()
            Timer2.Start()
        End If
    End Sub
End Class

enter image description here

I also have a video link on how it currently works link: https://youtu.be/JgBN4Uxdm_w I just want the sprites to animate I have 12 pictures of the soccer ball and 5 pictures for the player in my resources I just want them to animate.



Solution 1:[1]

This is my code for form 1 Public Class Form1

Public mv As Integer = 1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
    Form2.Show()
    Form2.Location = New Point(485, 100)
    Form2.Width = 400
    Form2.Height = 300
    Form3.Show()
    Form3.Location = New Point(860, 100)
    Form3.Width = 400
    Form3.Height = 300

    Me.Location = New Point(100, 100)
    Me.Width = 400
    Me.Height = 300

    Me.Location = New Point(100, 100)
    Me.Width = 400
    Me.Height = 300
    Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    OS1.Left = OS1.Left + 3
    Form2.OS2.Visible = False
    Form3.OS3.Visible = False
    If OS1.Left >= 350 Then
        Timer1.Stop()
        OS1.Visible = False
        Form2.mv = Me.mv
        Form2.OS2.Visible = True
        Form2.Timer1.Start()
    End If
End Sub
Private Sub animate()
    If mv = 1 Then
        OS1.Image = Image.FromFile("football1.png")
        mv = 2
    ElseIf mv = 2 Then
        OS1.Image = Image.FromFile("football2.png")
        mv = 3
    ElseIf mv = 3 Then
        OS1.Image = Image.FromFile("football3.png")
        mv = 4
    ElseIf mv = 4 Then
        OS1.Image = Image.FromFile("football4.png")
        mv = 1
    End If
End Sub

End Class

Form 2 code Public Class Form2

Public mv As Integer = 1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    OS2.Left = OS2.Left + 3
    OS2.Visible = True
    Form3.OS3.Visible = False
    If OS2.Left >= 350 Then
        Timer1.Stop()
        OS2.Visible = False
        Form3.mv = Me.mv
        Form3.OS3.Visible = True
        Form3.Timer1.Start()
    End If
End Sub
Private Sub animate()
    If mv = 1 Then
        OS2.Image = Image.FromFile("football1.png")
        mv = 2
    ElseIf mv = 2 Then
        OS2.Image = Image.FromFile("football2.png")
        mv = 3
    ElseIf mv = 3 Then
        OS2.Image = Image.FromFile("football3.png")
        mv = 4
    ElseIf mv = 4 Then
        OS2.Image = Image.FromFile("football4.png")
        mv = 1
    End If
End Sub

End Class

Form 3 code Public Class Form3

Public mv As Integer = 1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    OS3.Left = OS3.Left + 3
    OS3.Visible = True
    If OS3.Left >= 350 Then
        Timer1.Stop()
        OS3.Visible = False
    End If
End Sub
Private Sub animate()
    If mv = 1 Then
        OS3.Image = Image.FromFile("football1.png")
        mv = 2
    ElseIf mv = 2 Then
        OS3.Image = Image.FromFile("football2.png")
        mv = 3
    ElseIf mv = 3 Then
        OS3.Image = Image.FromFile("football3.png")
        mv = 4
    ElseIf mv = 4 Then
        OS3.Image = Image.FromFile("football4.png")
        mv = 1
    End If
End Sub

End Class

And the error message:

FileNotfoundException was unhandled C:\Users\63921\documents\visual studio 2010\Projects\ptptpttptptptpptptpt\ptptpttptptptptpptptpt\bin\Debugsoccerball1

enter image description here

enter image description here

Solution 2:[2]

You can set animation functions for OS1, OS2, OS3 respectively. Then pass a parameter directly in the form to make the animation coherent. But using pictures to animate is very inefficient. Here's a rather crude approach based on your code implementation.

Form1

    Public Dim mv As Integer = 1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Form2.Show()
    Form2.Location = New Point(485, 100)
    Form2.Width = 400
    Form2.Height = 300
    Form3.Show()
    Form3.Location = New Point(860, 100)
    Form3.Width = 400
    Form3.Height = 300

    Me.Location = New Point(100, 100)
    Me.Width = 400
    Me.Height = 300

    Me.Location = New Point(100, 100)
    Me.Width = 400
    Me.Height = 300
    Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    OS1.Left = OS1.Left + 3
    Form2.OS2.Visible = False
    Form3.OS3.Visible = False
    If OS1.Left >= 350 Then
        Timer1.Stop()
        OS1.Visible = False
        Form2.mv = Me.mv
        Form2.OS2.Visible = True
        Form2.Timer1.Start()
    End If
End Sub
Private Sub animate()
    If mv = 1 Then
        OS1.Image = Image.FromFile("football1")
        mv = 2
    ElseIf mv = 2 Then
        OS1.Image = Image.FromFile("football2")
        mv = 3
    ElseIf mv = 3 Then
        OS1.Image = Image.FromFile("football3")
        mv = 4
    ElseIf mv = 4 Then
        OS1.Image = Image.FromFile("football4")
        mv = 1
    End If
End Sub

Form2

Public Dim mv As Integer = 1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    OS2.Left = OS2.Left + 3
    OS2.Visible = True
    If OS2.Left >= 350 Then
        Timer1.Stop()
        OS2.Visible = False
        Form3.mv = Me.mv
        Form3.OS3.Visible = True
        Form3.Timer1.Start()
    End If
End Sub
Private Sub animate()
    If mv = 1 Then
        OS2.Image = Image.FromFile("football1")
        mv = 2
    ElseIf mv = 2 Then
        OS2.Image = Image.FromFile("football2")
        mv = 3
    ElseIf mv = 3 Then
        OS2.Image = Image.FromFile("football3")
        mv = 4
    ElseIf mv = 4 Then
        OS2.Image = Image.FromFile("football4")
        mv = 1
    End If
End Sub

Form3

Public Dim mv As Integer = 1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    OS3.Left = OS3.Left + 3
    OS3.Visible = True
    If OS3.Left >= 350 Then
        Timer1.Stop()
        OS3.Visible = False
    End If
End Sub
Private Sub animate()
    If mv = 1 Then
        OS3.Image = Image.FromFile("football1")
        mv = 2
    ElseIf mv = 2 Then
        OS3.Image = Image.FromFile("football2")
        mv = 3
    ElseIf mv = 3 Then
        OS3.Image = Image.FromFile("football3")
        mv = 4
    ElseIf mv = 4 Then
        OS3.Image = Image.FromFile("football4")
        mv = 1
    End If
End Sub

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2