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 8920119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:11:18+00:00 2026-06-15T06:11:18+00:00

I have a two dimensional array and I want to know how I can

  • 0

I have a two dimensional array and I want to know how I can refer to the rows and columns in it. Do I use [row,column] or [column,row]? I also have some graphics. Do I calculate the (x,y) coordinate set of each graphic with (row*size,col*size) or with (col*size,row*size)?

The whole two dimensional array is the building instructions for the grid.
Each element in the array refers to a piece of the grid.
I know how to construct this grid and its pieces and I know how to access and manipulate the array’s elements.

The problem is that when I construct the grid I have to calculate the x and y coordinate of each piece, but I just don’t know if my variable curRow should be used for the x or y coordinate. It’s similarly with the variable curCol.

My code is working, but it confuses me.
I think of it like the rows control the y coordinates and the columns control the x coordinates, because I just learned of the way matrices are referred to.
I ask, because it came to my mind that I am unsure of how to do this.
In the past I have used [row,column] to loop and (row*size,col*size) to position.

The code so far is:

function buildGrid(gridInfo:Array):Sprite {
    var displaySprite:Sprite = new Sprite();

    for(var curRow:uint=0;curRow<gridInfo.length;curRow++) {
        for(var curCol:uint=0;curCol<gridInfo[curRow].length;curCol++) {
            var infoRef:Object = gridInfo[curRow][curCol];//create reference for fast access

            var pieceGraphic:Shape = new Shape();
            pieceGraphic.graphics.beginFill(infoRef.fillColor);
            pieceGraphic.graphics.lineStyle(infoRef.borderThickness,infoRef.theBorderColor);
            pieceGraphic.graphics.drawRect(0,0,infoRef.sideLength,infoRef.sideLength);
            pieceGraphic.graphics.endFill();

            pieceGraphic.x = curRow*(infoRef.sideLength+infoRef.spaceX);//later use of graphic requires known x
            pieceGraphic.y = curCol*(infoRef.sideLength+infoRef.spaceY);//later use of graphic requires known y

            displaySprite.addChild(pieceGraphic);
        }
    }

    return displaySprite;
}
  • 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-15T06:11:19+00:00Added an answer on June 15, 2026 at 6:11 am

    It’s correct to refer to a two dimensional array with [row,column], but it’s easier with other variable names like curX and curY. It’s important to be consistent of what the indexes mean throughout the project and what indexes are used. To access the first elements in the array create a loop for rows or for curX and for the elements in the second dimension create a loop for columns or for curY.

    You can calculate coordinate sets (x,y) for graphics in a grid with (row*size,col*size) or (curX*size,curY*size), so your code is correct and doesn’t need to be changed.

    Remember that rows are horizontal and columns are vertical.

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

Sidebar

Related Questions

I have a quadratic matrix(two-dimensional dynamic array of pointers) and need to change rows/columns
I have a two-dimensional array and want to sort it by name. I would
I have a two dimensional array with coordinates and i want to make the
I want to create two dimensional array of buttons in windows form. I have
I want to define a dynamic two-dimensional array in python. I don't know how
I have a 3 dimensional array. I want to assign only the first two
I have a two dimensional array having elements of a matrix I want to
I have two-dimensional array and I want replace second of two-dimensional array on random
I have a two dimensional array in php and I want to get the
I have a two dimensional array: object[,] cells; After initializing it, I want to

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.