So I am trying to make a tile map editor/reader to create and interact with maps like this , so essnetially I am wondering what the best way to go about this would be. I have not done anyhting graphical in programming in a long time and yeah, I was thinking an arary of jlabels on a jframe? Anyone have any suggestions / ideas? thanks

``````    I'd recommend using an array to create a grid on the screen. Then you can assign each cell a value. This value determines which bitmap is displayed in the cell.

e.g. If we assign the value 1 to door.jpg and then say
(3,2) = 1
The system then paints the door.jpg image in the cell (3,2).

Hope this Helps
``````

Thanks, I think I could do this, do you have any recomondations on how to actaully make the grid or how to display this? Im more confused on the actual code for displaying, say a grid like you said, I know how to make an array but how could i make a visual array that is say 32x32? Thanks agian

Ok so first we need to create a 2 dimensional array. To paint the grid, we just need to create a simple loop that loops through each item in the array. As far as referencing the grid goes, the easiest way is to create a switch for grid(x,y) and find the value of each cell.

``````    int grid[][] = new int[32][32]; //this creates our 32*32 grid

public void paintComponent(Graphics g){

grid[2][2]=1; //this is how values are assigned to each cell
grid[2][3]=2;

//here we create 2 loops x and y to go through each item in the grid array

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

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

//Switch to determine Cell value
//and therefore cell colour
switch (grid[x][y]){

//default
case(0):
g.setColor(Color.GREEN);
break;

//Water
case(1):
g.setColor(Color.BLUE);
break;

//dirt
case(2):
g.setColor(Color.DARK_GRAY);
break;

}

//draw the filled rectangle in specified color
g.fillRect(x*32,y*32,32,32);

//draw borders
g.setColor(Color.BLACK);
g.drawRect(x*32,y*32,32,32);

}
}
repaint();
}
``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.