Drawing My Tiles

I have an array named “tile”, and it’s length is 61. I want to draw each one on the screen, and am assuming a for loop would be the best way. I’ve never been good with the math/concept side of gaming, so I was hoping somebody would point me in the right direction.

I know this is wrong, but I made it to help show you what I mean:

for(int i = 0; i < tile.length; i++) {

	for(int x = 0; x < 36; x++) {
	
		for(int y = 0; y < 25; y++) {
		
		tile[i] = new Tile(x * 16, y * 16);
		
		}
	
	}

}

Thanks!

That’s what I usually make:



Tile[] tiles;
int[][] map = {
		{1, 1, 1, 1,},
		{1, 0, 0, 1,},
		{1, 0, 0, 1,},
		{1, 1, 1, 1,}
}


public void buildMap(){
int mapW =map[0].lenght;
int mapH = map.lenght;

tiles= new Tile[mapW*mapH]

for(int x=0; x<mapW;x++){

     for(int y=0; y<mapH;y++){

       tiles[x+y*mapW]= new Tile(x * 16, y * 16);

    }
}

}

public void renderMap(){

for(int x=0; x<mapW;x++){

     for(int y=0; y<mapH;y++){

       tiles[x+y*mapW].render;

    }
}

}


I think that it’s enough understable, if not, ask me anything :slight_smile:

For what I look from your X and Y loop, you’re going to create 36x25 tiles map. Then your problems are:

  • Your 61 isn’t enough. You need 36x25=900 length tiles.
  • Your loops are wrong. Your tile[ i ] will be always Tile(3616, 2516) whatever the i is.
  • You still have problem on using nested loop. Try a simpler case then map drawing. Or if you confused, use 2D array.

Actually, in my Tile class I was already multiplying each number by 16 (16x16 images) to make it easier.

Still make no sense to your problem. Your nested loop for x and y doesn’t affect result of i literation :slight_smile: