This is how I currently check collision for my tile map:
int[,] layer;
for (x = 0; ...)
{
for (y = 0; ...)
{
//Do collision checks here, based on index.
}
}
This is the alternative I'm thinking of:
List<Collision> collisions;
for (i = 0; i < collisions.Count; i++)
{
//Check for "MovingObject to Collision" here.
}
I would assume that since I'm switching from two for
loops to just one, it would be faster.
- Performance-wise, does it matter what I iterate through with a
for
loop? - Out of curiosity, does it matter what I iterate through in a
foreach
loop?