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
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.)
Basically, this code:
mapArraymapArraymapArraymapArrayint 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!