-1
I’m trying to make a little 2D game, in it when the character moves the walls also move in a way that looks like some kind of game, however using timers would be a bad idea because when I add too many walls (Picturebox) would be too slow the form, then the other option would be to create a Thread to separate the work, the code I use to move the walls are there.
Private Scene As New Thread(AddressOf MoveWalls)
Private Sub MoveWalls()
For Each Wall As PictureBox In Controls.OfType(Of PictureBox)()
If Not Wall.Tag = "Player" Then
Wall.Location = New Point(Wall.Location.X + X2, Wall.Location.Y + Y2)
End If
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Scene.Start()
End Sub
OBS: The player is also a Picturebox so for Thread not to use as a wall I changed the Player Tag to Player
When I run the application nothing happens, but I added a label to test if it could change the value and in doing so appeared an error on the screen.
I even tried the solution tip that he recommends but did not succeed. Link to recommended solution Can anyone tell me if it is possible to change the location of the walls using Thread? If yes I need help, if not some better idea?
Why didn’t you succeed by following the link you posted? It gives clear examples of what you should do.
– Bruno Warmling
I have a bit of experience in Vb.net, but in all this time I only touched twice with thread (counting on this one), I made up my code following this solution tip but I did not get result.
– Deivison