Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Launching Projectile [Game Issue]
#10
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
My Blog | My Setup | My Videos | Have a wonderful day.


Messages In This Thread
Launching Projectile [Game Issue] - by Vinwarez - 07-13-2012, 01:08 PM
Re: Launching Projectile [Game Issue] - by brandonio21_phpbb3_import2 - 07-13-2012, 03:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Full screen game overlay? Ecnarf 1 8,191 01-29-2013, 09:14 AM
Last Post: xolara
  Dual Menu Strip Issue Moldraxian 3 16,049 08-15-2012, 12:36 PM
Last Post: brandonio21
  MySQL Database Issue Moldraxian 7 27,795 08-13-2012, 08:58 PM
Last Post: brandonio21
  Module Issue Vinwarez 18 56,222 07-24-2012, 11:47 PM
Last Post: Vinwarez
  Remove Enemy [Game Issue] Vinwarez 3 13,713 07-14-2012, 02:15 PM
Last Post: brandonio21

Forum Jump:


Users browsing this thread: 1 Guest(s)