我正在尝试为Java 上的游戏制作等距地图,但我找不到这样做的方法。我需要为JLabel
等轴测图的每个多边形添加一个,以便可以paint()
用于每个位置。如何JLabel
为我绘制的每个多边形添加一个?我无法得到它。我已经有了绘制等轴测图每个位置的算法,如下所示:
//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);
}
}
}
非常感谢你们