I'm making a 2d sidescrolling game and im trying to use a 2dimensional or so-to-say tileset. My friend gave me some code that he had been using for his games but his code only supports 1 dimension.
public void DrawMap(Texture2D tilesheet, SpriteBatch spriteBatch)
{
for (int x = 0; x < map.GetLength(1); x++)
{
for (int y = 0; y < map.GetLength(0); y++)
{
spriteBatch.Draw(tilesheet, new Vector2((x * 64) , (y * 64)), new Rectangle(map[y, x] * 64, 0, 64, 64), Color.White);
}
}
}
this is where the problem appears, because it's a group project and we recieve graphics from a graphics designer and we have too many tiles(64x64 in size) to fit into one row of texture that is supported for xna(4096 pixels i think). I barely understand the code that my friend gave me and that's probably where the issue comes from. If anyone knows how to make the draw method support 2 dimensions so that i can use tilesets the are the dimensions(512x512 as an example) instead of 64x4992(which my current tileset is at).
public Level()
{
map = new int[14, 50]
{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17,18,19,20,21,22,23,24,17,18,19,20,21,22,23,24,2},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25,26,27,28,29,30,31,32,25,26,27,28,29,30,31,32,2},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,33,34,35,36,37,38,39,40,33,34,35,36,37,38,39,40,2},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41,42,43,44,45,46,47,48,41,42,43,44,45,46,47,48,2},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,5,0,0,0,0,49,50,51,52,53,54,55,56,49,50,51,52,53,54,55,56,2},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,57,58,59,60,61,62,63,64,57,58,59,60,61,62,63,64,2},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,11,0,0,0,0,0,0,0,0,0,65,66,67,68,69,70,71,72,65,66,67,68,69,70,71,72,2},
{3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,6,7,2,12,13,3,3,3,3,3,3,3,3,3,73,74,75,76,77,78,79,80,73,74,75,76,77,78,79,80,2},
{2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}};
overlay = new int[14, 50];
background = new int[14,50];
}
public void DrawMap(Texture2D tilesheet, SpriteBatch spriteBatch)
{
for (int x = 0; x < map.GetLength(1); x++)
{
for (int y = 0; y < map.GetLength(0); y++)
{
//http://imgur.com/1r9VUUN
spriteBatch.Draw(tilesheet, new Vector2((x * 64), (y * 64)), new Rectangle((map[x, y] % 8) * 64, (map[x, y] / 8) * 64, 64, 64), Color.White);
}
}
}
So im editing my maps in Tiled and i realized that tiled counts 1-2-3-4-5, not 0-1-2-3-4-5. So if you looks at my tileset(commented away in the draw method imgur link) you see that i have a blank space before the first tile, but this means that every tile has their positionvalue + 1 in xna, which might be why im having issues drawing it, because the tile im trying to draw doesn't exist in the tileset.

