visual-studio-2010animationvb.net-2010

Vb.net animation sonic the hedgehog


Why does my walk not work but the run works properly sonic the hedgehog animation. enter image description here

Public Class Form1

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        PictureBox1.Image = My.Resources.SONICRUN1_removebg_preview
        Timer1.Stop()
        Timer2.Start()
    End Sub
    
    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        PictureBox1.Image = My.Resources.SONICRUN2_removebg_preview
        Timer2.Stop()
        Timer1.Start()
    End Sub
    
    Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
        PictureBox1.Image = My.Resources.SONICRUN3_removebg_preview
        Timer3.Stop()
        Timer2.Start()
    End Sub
    
    Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
        PictureBox1.Image = My.Resources.SONICRUN4_removebg_preview
        Timer4.Stop()
        Timer3.Start()
    End Sub
    
    Private Sub btnRUN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRUN.Click
        Timer1.Enabled = True
        Timer5.Enabled = False
    End Sub
    
    Private Sub btnWALK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWALK.Click
        Timer5.Enabled = True
        Timer1.Enabled = False
    End Sub
    
    Private Sub Timer5_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer5.Tick
        PictureBox1.Image = My.Resources.SONICWALK1_removebg_preview
        Timer5.Stop()
        Timer4.Start()
    End Sub
    
    Private Sub Timer6_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer6.Tick
        PictureBox1.Image = My.Resources.SONICWALK2_removebg_preview
        Timer6.Stop()
        Timer5.Start()
    End Sub
    
    Private Sub Timer7_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer7.Tick
        PictureBox1.Image = My.Resources.SONICWALK3_removebg_preview
        Timer7.Stop()
        Timer6.Start()
    End Sub
    
    Private Sub Timer8_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer8.Tick
        PictureBox1.Image = My.Resources.SONICWALK4_removebg_preview
        Timer8.Stop()
        Timer7.Start()
    End Sub
    
    Private Sub Timer9_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer9.Tick
        PictureBox1.Image = My.Resources.SONICWALK5_removebg_preview
        Timer9.Stop()
        Timer8.Start()
    End Sub
    
    Private Sub Timer10_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer10.Tick
        PictureBox1.Image = My.Resources.SONICWALK6_removebg_preview
        Timer10.Stop()
        Timer9.Start()
    End Sub
    
    Private Sub Timer11_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer11.Tick
        PictureBox1.Image = My.Resources.SONICWALK7_removebg_preview
        Timer11.Stop()
        Timer10.Start()
    End Sub
    
    Private Sub Timer12_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer12.Tick
        PictureBox1.Image = My.Resources.SONICWALK8_removebg_preview
        Timer12.Stop()
        Timer11.Start()
    End Sub

End Class

I tried doing it again erased it and it still didn't walk he was still running.

When I press the run it works ok. But when I press the walk it won't do the walk animation! Also when I start the program it starts running already. I want it to not run when the program is started I want it to run when I press the buttons.


Solution

  • The Run command starts Timer1. When Timer1 is done it starts Timer2. When Timer2 is done it goes back to Timer1. So run is just toggling back and forth between Timer1 and Timer2.

    The Walk command starts Timer5, which starts Timer4 --> Timer3 --> Timer2 --> Timer1...and then gets stuck in the Run cycle toggling between Timer1 and Timer2.

    What should the Walk sequence be?

    If you don't want anything to be animating, then select each Timer and set the Enabled property to FALSE. Make sure you aren't turning any Timers on in the Load() event of your Form.

    Try something like this out:

    Public Class Form1
    
        Private runSequence() As Image
        Private walkSequence() As Image
        Private runIndex As Integer = -1
        Private walkIndex As Integer = -1
        Private WithEvents trmRun As New System.Windows.Forms.Timer
        Private WithEvents trmWalk As New System.Windows.Forms.Timer
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            runSequence = {My.Resources.SONICRUN1_removebg_preview, My.Resources.SONICRUN2_removebg_preview,
                My.Resources.SONICRUN3_removebg_preview, My.Resources.SONICRUN4_removebg_preview}
            walkSequence = {My.Resources.SONICWALK1_removebg_preview, My.Resources.SONICWALK2_removebg_preview,
                My.Resources.SONICWALK3_removebg_preview, My.Resources.SONICWALK4_removebg_preview,
                My.Resources.SONICWALK5_removebg_preview, My.Resources.SONICWALK6_removebg_preview,
                My.Resources.SONICWALK7_removebg_preview, My.Resources.SONICWALK8_removebg_preview}
    
            trmRun.Interval = 100
            trmRun.Enabled = False
            trmWalk.Interval = 100
            trmWalk.Enabled = False
        End Sub
    
        Private Sub btnRUN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRun.Click
            trmWalk.Stop()
            trmRun.Start()
        End Sub
    
        Private Sub btnWALK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWalk.Click
            trmRun.Stop()
            trmWalk.Start()
        End Sub
    
        Private Sub trmRun_Tick(sender As Object, e As EventArgs) Handles trmRun.Tick
            runIndex = runIndex + 1
            If runIndex = runSequence.Length Then
                runIndex = 0
            End If
            PictureBox1.Image = runSequence(runIndex)
        End Sub
    
        Private Sub trmWalk_Tick(sender As Object, e As EventArgs) Handles trmWalk.Tick
            walkIndex = walkIndex + 1
            If walkIndex = walkSequence.Length Then
                walkIndex = 0
            End If
            PictureBox1.Image = walkSequence(walkIndex)
        End Sub
    
    End Class