'How to make the Form 2 and three animate while the buttons are on form 1
I want my form 2 and 3 to animate while the buttons are on form 1 and when it goes to form 2 it doesn't stop it continues animating.
FORM 1 CODE:
Public Class Form1
Private runSequence() As Image
Private walkSequence() As Image
Private idleSequence() As Image
Private runIndex As Integer = -1
Private walkIndex As Integer = -1
Private idleIndex As Integer = -1
Private WithEvents trmRun As New System.Windows.Forms.Timer
Private WithEvents trmWalk As New System.Windows.Forms.Timer
Private WithEvents trmIdle As New System.Windows.Forms.Timer
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Form2.PictureBox1.Visible = False
Form3.PictureBox1.Visible = False
Form2.Show()
Form3.Show()
Me.Width = 300
Form2.Width = 300
Form3.Width = 300
Me.Height = 300
Form2.Height = 300
Form3.Height = 300
Me.Location = New Point(100, 100)
Form2.Location = New Point(385, 100)
Form3.Location = New Point(670, 100)
runSequence = {My.Resources.sonic1, My.Resources.sonic2,
My.Resources.sonic3, My.Resources.sonic4}
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}
idleSequence = {My.Resources.SONICIDLE1_removebg_preview, My.Resources.SONICIDLE2_removebg_preview,
My.Resources.SONICIDLE3_removebg_preview, My.Resources.SONICIDLE4_removebg_preview,
My.Resources.SONICIDLE5_removebg_preview, My.Resources.SONICIDLE6_removebg_preview,
My.Resources.SONICIDLE7_removebg_preview, My.Resources.SONICIDLE8_removebg_preview,
My.Resources.SONICIDLE9_removebg_preview}
trmRun.Interval = 100
trmRun.Enabled = False
trmWalk.Interval = 100
trmWalk.Enabled = False
trmIdle.Interval = 170
trmIdle.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()
trmIdle.Stop()
End Sub
Private Sub btnWALK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWALK.Click
trmRun.Stop()
trmWalk.Start()
trmIdle.Stop()
End Sub
Private Sub trmRun_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles trmRun.Tick
runIndex = runIndex + 1
PictureBox1.Left = PictureBox1.Left + 6
If runIndex = runSequence.Length Then
runIndex = 0
Timer1.Stop()
Timer2.Start()
End If
PictureBox1.Image = runSequence(runIndex)
End Sub
Private Sub trmWalk_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles trmWalk.Tick
walkIndex = walkIndex + 1
PictureBox1.Left = PictureBox1.Left + 4
If walkIndex = walkSequence.Length Then
walkIndex = 0
Timer1.Stop()
Timer2.Start()
End If
PictureBox1.Image = walkSequence(walkIndex)
End Sub
Private Sub btnIDLE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIDLE.Click
trmRun.Stop()
trmWalk.Stop()
trmIdle.Start()
Timer2.Stop()
End Sub
Private Sub trmIdle_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles trmIdle.Tick
idleIndex = idleIndex + 1
If idleIndex = idleSequence.Length Then
idleIndex = 0
End If
PictureBox1.Image = idleSequence(idleIndex)
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If PictureBox1.Left >= 275 Then
Timer2.Stop()
Form2.PictureBox1.Visible = True
Form2.Timer1.Start()
End If
End Sub
End Class
The thing is I want it to animate on form 2 and 3 without having to put buttons on form 2 and three I want the sprite to be controlled from buttons on the form 1. And I want it to be like if I pressed run on form 1 before it goes to form 2 the continuing animation will be run or walk if I pressed walk before. Video Example of the current project: https://youtu.be/DLb68CXy0dI
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
