Vb.net 动画刺猬索尼克

Vb.net animation sonic the hedgehog

为什么我的走路不起作用,但 运行 可以正常运行刺猬动画。

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

我试了一遍擦掉了还是没走 他还在运行ning.

当我按下 运行 时,它工作正常。但是当我按下步行时,它不会执行步行动画!此外,当我启动程序时,它已经启动 运行ning。我希望它在程序启动时不 运行 我希望它在我按下按钮时 运行。

运行 命令启动 Timer1。当 Timer1 完成后,它会启动 Timer2。当 Timer2 完成后,它返回到 Timer1。所以 运行 只是在 Timer1 和 Timer2 之间来回切换。

Walk 命令启动 Timer5,后者启动 Timer4 --> Timer3 --> Timer2 --> Timer1...然后卡在 Timer1 和 Timer2 之间的 运行 循环切换中。

Walk 序列应该是什么?

如果您不想让任何东西具有动画效果,则 select 每个计时器并将启用 属性 设置为 FALSE。确保您没有在表单的 Load() 事件中打开任何计时器。

尝试这样的事情:

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