I am trying to do a isometric map for a game on Java, but I can’t find a way to do this. I need to add a JLabel for each polygon of the isometric map, so I can use paint() for each position. How can I add a JLabel for each polygon I draw? I can’t get it. I already have my algorithm to draw each position of my isometric map, something like this:
//L is the width of the map (that will be the framw width)
//N will be the number of COLUMN, like N*N will be the total number of positions.
//The first position (a,b) that will be
a=L / (2*N+1)
b=a . tan(30º
for (int y = 0; y < N; y++) {
if (y % 2 == 0) { // Se y é PAR
for (int x = 0; x < N; x++) {
Polygon p = new Polygon();
p.addPoint(x * a * 2 + a, y * b);
p.addPoint(x * a * 2 + 2 * a, y * b + b);
p.addPoint(x * a * 2 + a, y * b + 2 * b);
p.addPoint(x * a * 2, y * b + b);
g.drawPolygon(p);
}
} else { // if Y is odd
for (int x = 0; x < N; x++) {
Polygon p = new Polygon();
p.addPoint(x * a * 2 + 2 * a, y * b);
p.addPoint(x * a * 2 + 3 * a, y * b + b);
p.addPoint(x * a * 2 + 2 * a, y * b + 2 * b);
p.addPoint(x * a * 2 + a, y * b + b);
g.drawPolygon(p);
}
}
}
Thanks alot in advance guys
Layout and drawing are really quite different. Layout isn’t about exact positioning. You may as well just use drawChars on the Graphics object in the position you want, or cast it into a Graphics2D object and use drawString.