How to save data of two for loops in one array?

Posted by Homer_Simpson on Stack Overflow See other posts from Stack Overflow or by Homer_Simpson
Published on 2012-09-15T15:29:18Z Indexed on 2012/09/15 15:37 UTC
Read the original article Hit count: 126

Filed under:
|

I have two for loops and I wanna save that data in one array. The first for loop will create 5 rectangles in the array. After that, the second for loop will create 5 rectangles and add them to the array. But something doesn't work. I get that "Index was outside the bounds of the array" error message in the last line of the code and I don't know what to change. int framewidth = texture.Width / sourceRects.Length; int frameheight = texture.Height;

private void vorrück(Rectangle[] sourceRects, int framewidth, int frameheight) 
    { 
        int doublelenght = sourceRects.Length * 2; 
        for (int i = 0; i < sourceRects.Length; i++) 
            sourceRects[i] = new Rectangle(i * framewidth, 0, framewidth, frameheight); 
        for (int normallenght = sourceRects.Length; normallenght < doublelenght; normallenght++) 
            sourceRects[normallenght] = new Rectangle((sourceRects.Length - 1 - normallenght) * framewidth, 0, framewidth, frameheight);      
    }

© Stack Overflow or respective owner

Related posts about c#

Related posts about XNA