-1
public class Hexagon extends JPanel {
// Team that controls the hexagon
public int controller; // 0 neutral // 1 is team 1 // 2 is team 2
// Color of the hexagon
// /* All attributes of the board, used for size an boarder etc... */ Board board
// /* Determines where the hexagon sits on the game board */ int position
public static void main(String args[])
{
JFrame j = new JFrame();
j.setSize(350, 250);
for(int i = 0; i < 121; i++)
{
Hexagon hex = new Hexagon();
j.add(hex);
}
j.setVisible(true);
}
@Override
public void paintComponent(Graphics shape)
{
super.paintComponent(shape);
Polygon hexagon = new Polygon();
// x, y coordinate centers, r is radius from center
Double x, y;
// Define sides of polygon for hexagon
for(int i = 0; i < 6; i++)
{
x = 25 + 22 * Math.cos(i * 2 * Math.PI/6);
y = 25 + 22 * Math.sin(i * 2 * Math.PI/6);
hexagon.addPoint(x.intValue(), y.intValue());
}
// Automatic translate
hexagon.translate(10, 10);
// How do I manually control translate?
shape.drawPolygon(hexagon);
}
}
如何手动平移多边形?我需要做它来创建一个游戏板。到目前为止,我只完成了多边形的自动翻译,这绝对是我不需要的。手动平移多边形
请勿在截图中发布代码。将其作为文本发布。 – khelwood
这个问题还不清楚。更具体一些。 –
它怎么可能更清楚?我正在尝试翻译多边形,并且我已经评论了自动翻译多边形的位置,这不是我正在尝试执行的操作。 –