Vb.net more performance for moving objects

I have a mission to make a small game for a school project. Boxes with pictures moved by a timer for walking enemies. If there are about 5 or 6 boxes of moving images in the form, my application gets problems and delays. After I kill some enemies (remove them from the collection of form / panel controls), it will return smooth.

I think the enemy movement cycle is too complicated, but I don’t know how to make it easier.

Private Sub TimerEnemyMovement_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerEnemyMovement.Tick
    For Each Enemy As Control In PanelBackground.Controls
        If Enemy.Name.Substring(0, 5) = "Enemy" Then
            _enemy.MoveEnemy(Enemy, 2)
        End If
    Next
End Sub

I also thought about multithreading, but not sure if this will solve the problem, and there is a problem that I cannot access the controls of my main form.

You know, I have little knowledge about vb.net

Any ideas how to fix this backlog?

+3
5

:

Private Sub TimerEnemyMovement_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerEnemyMovement.Tick
    SuspendLayout()
    For Each Enemy As Control In PanelBackground.Controls
        If Enemy.Name.Substring(0, 5) = "Enemy" Then
            _enemy.MoveEnemy(Enemy, 2)
        End If
    Next
    ResumeLayout()
End Sub
+2

VB.NET WinForm . , .

VB.NET WPF (Windows Presentation Framework), .

0

,

a) , , / b) , , .. ( ) "" , BMP ,

0
source

Do all enemies need to move at the same time? Do something faster?

if there are 6 enemies, you can move 1,3,5 to the first tick, then 2.4.6 to the next tick, etc.

?

0
source

I use XNA to create a simple game, it was really great. Although VB.NET is not officially supported, you can make it work. It is optimized for decoration and a large number of animated objects.

0
source

Source: https://habr.com/ru/post/1747890/


All Articles