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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:50:18+00:00 2026-05-30T08:50:18+00:00

Hey I was wondering how I would go about coding a way to load

  • 0

Hey I was wondering how I would go about coding a way to load and draw a 2d level from a 2d array in XNA 4.

Here is what I have so far.

I am loading my array like this

        mapArray = new int[,]
        {
            {0, 0, 0, 0},
            {2, 0, 0, 2},
            {0, 0, 0, 0},
            {1, 1, 1, 1}
        };

Then I get stuck I cannot seem to figure out how to draw the array, I know I need to use a for loop to check through the array but this is my first time working with 2d arrays.

Is there anyone that could explain in detail how I would go about drawing this?

Thanks

-Josh

  • 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-05-30T08:50:19+00:00Added an answer on May 30, 2026 at 8:50 am

    You might be able to use something like this in order to check for what number is in each slot: (Note: This is untested code… but the code’s skeleton comes from a tutorial found here.)

    using System;
    
    class Program
    {
        static void Main()
        {
            mapArray = new int[,]
            {
                {0, 0, 0, 0},
                {2, 0, 0, 2},
                {0, 0, 0, 0},
                {1, 1, 1, 1}
            };
    
            // Get upper bounds for the mapArray.
            int bound0 = mapArray.GetUpperBound(0);
            int bound1 = mapArray.GetUpperBound(1);
    
            // Use for-loops to iterate over the mapArray elements.
            for (int i=0; i<=bound0; i++)
            {
                for (int j=0; j<=bound1; j++)
                {
                    int value = mapArray[i, j];
                    Console.WriteLine(value);
                }
            }
        }
    }
    

    Basically, this code:

    • initializes your mapArray
    • checks for the ends (bounds) of both dimensions of your mapArray
    • loops through the first dimension of the mapArray
    • then, while still looping through first dimension, there is a second loop that goes through second dimension of the mapArray
    • in the middle of both of these loops, your value is found: int value = mapArray[i, j];

    Here is a reference for 2D array loops for C#. And here is a reference on arrays in C#. Hope this helps a little!

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

Sidebar

Related Questions

Hey just wondering how I can draw multiple rectangle objects in C# but have
Hey, I'm just wondering if it would be possible to convert videos to mp3
Hey, I'm using D 1.041 with Tango 0.99.8 and was wondering how I would
Hey I was just wondering if there is a cool one liner that would
Hey I was wondering if there were any way to upload images in ASP?
Hey all, I am wondering what the best way to do the following is:
Hey, anyone have any idea what the best way to allow users to save
Hey everyone, I was wondering how would I start programming an interface to trading
Hey, I am wondering how to extract the data from a table in a
Hey, I have a question regarding code structure, and was wondering what the best

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.