Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8244363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:49:46+00:00 2026-06-07T21:49:46+00:00

This while loop does not properly store the values needed into the rectangle array.

  • 0

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);
*/
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T21:49:47+00:00Added an answer on June 7, 2026 at 9:49 pm

    You need to reset n to 0 when you are done with each inner loop

    int n = 0;
    int n2 = 0;
    while (n2 < 5)
        {
            n = 0;
            while (n < 4)
            {
                Rectangles[n2, n] = new Rectangle
                     (sizeOfEachSpriteX * n2, 
                      sizeOfEachSpriteY * n, 
                      sizeOfEachSpriteX, 
                      sizeOfEachSpriteY);
                n++;
            }
            n2++;
        }
    

    What’s happening is that for n2 > 0, n is already 4, so the inner loop is never executed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I've been stuck on this do-while loop not working for about two hours.
I've run into this while writing a Traveling Salesman program. For an inner loop,
My while loop does not exit when Ctrl+C is pressed. It seemingly ignores my
This loop does not terminate after I type x. I'm really new to Ruby,
I am wondering why the table variables inside while loop does not behave like
I have a function creating entries via grid() like this: (replace while-loop with function,
I am trying update text views while this loop is processing. Here is my
This is a working snippet of a while loop : while(total_bytes_read != fsize){ while((nread
I'm performing a while loop in C#, this is going through some records being
I have created this function to check abecedarian with while loop (A word is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.