This while loop does not properly store the values needed into the rectangle array. The rectangles are used for pulling sprites from a sprite sheet. The commented out code below works perfectly. The inner loop works perfectly for setting the first row, but adding the outer loop messes up everything. The value for the sizeOfEachSpriteX and sizeOfEachSpriteY are both 32 (the sprites are square). The spritesheet size is 96 wide by 128 tall. It is 4 rows, and 3 columns of sprites. The goal is to have the rectangle be declared as Rectangles [which row, which column], as the commented out code achieves. It appears the later iterations overwrite the first iterations’ data, and destroy the whole process. I’m quite confused!
int n = 0;
int n2 = 0;
while (n2 < 5)
{
while (n < 4)
{
Rectangles[n2, n] = new Rectangle
(sizeOfEachSpriteX * n2,
sizeOfEachSpriteY * n,
sizeOfEachSpriteX,
sizeOfEachSpriteY);
n++;
}
n2++;
}
/* This code works perfectly.
Rectangles[0,0] = new Rectangle(0,0,32,32);
Rectangles[0,1] = new Rectangle(0,32,32,32);
Rectangles[0,2] = new Rectangle(0,64,32,32);
Rectangles[0,3] = new Rectangle(0,96,32,32);
Rectangles[1,0] = new Rectangle(32,0,32,32);
Rectangles[1,1] = new Rectangle(32,32,32,32);
Rectangles[1,2] = new Rectangle(32,64,32,32);
Rectangles[1,3] = new Rectangle(32,96,32,32);
Rectangles[2,0] = new Rectangle(64,0,32,32);
Rectangles[2,1] = new Rectangle(64,32,32,32);
Rectangles[2,2] = new Rectangle(64,64,32,32);
Rectangles[2,3] = new Rectangle(64,96,32,32);
*/
You need to reset n to 0 when you are done with each inner loop
What’s happening is that for n2 > 0, n is already 4, so the inner loop is never executed.