07-13-2012, 03:21 PM
Oh okay! Alright, this is an easy fix. So this error is popping up because we are modifying the array as we are scrolling through it, so the solution to this is to create an array to keep track of the bullets that we need to remove and remove them once we are finished. So something like this...
Code:
Public Sub PlayerBullets_Act()
'This method moves the player bullets and detects their collisions. It should be called every
'time the timer ticks
Dim bulletsToRemove As New List(Of PictureBox)
For Each bullet As PictureBox In playerBullets
If (bullet.Location.Y <= 0) Then
'The bullet has moved off of the screen, we need to remove it to conserve system resources
bulletsToRemove.Add(bullet)
End If
'TODO: Check for collisions with enemies here
bullet.Location = New System.Drawing.Point(bullet.Location.X, bullet.Location.Y - 2) 'Move the bullet up
Next
'Now we remove the bullets
For Each bullet As PictureBox In bulletsToRemove
Controls.Remove(bullet)
playerBullets.Remove(bullet)
Next
End Sub