I'm working on a Flappy Bird clone as an exercise, for I've recently started programming on XNA and I'm stuck on this error that I cannot understand.
I included the following code inside the Update() function, which's job is to delete the pipes when they go off screen lest they infinitely move leftwards while more are created:
//Pipe despawner
foreach (var pipe in pipes)
{
if (pipe.position1.X <= -180)
{
pipes.Remove(pipe);
}
}
The game runs fine until the first pipe goes offscreen and the debugger pauses and signals this part of the code with the following message:
An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
Additional information: Colección modificada; puede que no se ejecute la operación de enumeración.
I'm sorry the second part is in spanish, it's my system's language, but hopefully you know how to solve the problem anyway.
I believe I could simply not include this part of the code, given the simplicity of the game and, by consequence, the small toll that infinitely spawning pipes take on performance, but I'd rather not adopt this practice as soon as I start learning game programming.