I ended up doing this:
foreach (clBullet b in spriteList)
{
//if(b.position.X < 300)
b.Update(gameTime, Game.Window.ClientBounds);
}
if (spriteList.Count > 0)
{
if (objBullet.position.X > 300)
spriteList.Remove(objBullet);
}
I don't get the error anymore.
Pretty sure there has to be a better way. It was an enumerator error that was popping up. I think the problem was that I was trying to remove something in the list while going through the list itself. Lists are still a new area for me, so i do not quite understand the way it works. I figured it would be best to handle bullets and other weapons this way and possibly enemies as well.
Here is the other code that may or may not help:
if (Keyboard.GetState().IsKeyDown(Keys.Z))
{
if (shootTimer == 1.5f)
{
objBullet = new clBullet(Game.Content.Load<Texture2D>(@"Content/Images/sprBullet1"), new Vector2(objPlayer.position.X+8, objPlayer.position.Y+8), new Point(15, 5), 5, new Point(0, 0), new Point(0, 0), new Vector2(1, 1), true, 200);
spriteList.Add(objBullet);
shootTimer -= 0.1f;
}
}
if (shootTimer < 1.5f)
{
shootTimer -= 0.1f;
}
if (shootTimer <= 0.0f)
{
shootTimer = 1.5f;
}
foreach (clBullet b in spriteList)
{
if(b.position.X < 300)
b.Update(gameTime, Game.Window.ClientBounds);
}
if (spriteList.Count > 0)
{
if (objBullet.position.X >= 300)
spriteList.Remove(objBullet);
}
I need to put in some code to draw the number of objects in the list to make sure it is actually removing the bullets.