我正在嘗試爲Java遊戲做一個isometric地圖,但我無法找到一個方法來做到這一點。我需要爲等軸測圖的每個多邊形添加一個JLabel
,因此我可以爲每個位置使用paint()
。我如何爲每個繪製的多邊形添加一個JLabel
?我無法得到它。我已經有我的算法得出我的軸測圖的每一個位置,這樣的事情:如何在多邊形內添加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);
}
}
}
非常感謝提前傢伙
JLabel是否必須在多邊形內?添加它到底是什麼問題?此外你在繪製你的多邊形? –
發佈您的SSCCE,顯示多邊形的繪畫以及框架的大小如何影響多邊形。 – camickr