这是我画的六边形:
a-b-c-d-e-
-f-g-h-i-j
k-l-m-n-o-
-p-q-r-s-t
u-v-w-x-y-
破折号是空的位置 - 他们的存在:表示该数据将认为它这样
public Hexagon(float pX, float pY, float pSize) {
super(pX, pY, pSize, pSize);
// setColor(1, 0, 0);
setAlpha(0);
float x1, x2, y1, y2;
float lineWidth = 3;
x1 = 0; y1 = pSize/2;
x2 = pSize/4; y2 = (pSize * ((2 - (float)Math.sqrt(3))/4)); // Done
Line line = new Line(x1, y1, x2, y2);
line.setLineWidth(lineWidth);
attachChild(line);
x1 = x2; y1 = y2;
x2 = pSize * .75f; // Done
line = new Line(x1, y1, x2, y2);
line.setLineWidth(lineWidth);
attachChild(line);
x1 = x2; y1 = y2;
x2 = pSize; y2 = pSize/2; // Done
line = new Line(x1, y1, x2, y2);
line.setLineWidth(lineWidth);
attachChild(line);
x1 = x2; y1 = y2;
x2 = pSize * .75f; y2 = pSize - (pSize * ((2 - (float)Math.sqrt(3))/4)); // Done
line = new Line(x1, y1, x2, y2);
line.setLineWidth(lineWidth);
attachChild(line);
x1 = x2; y1 = y2;
x2 = pSize/4; // Done
line = new Line(x1, y1, x2, y2);
line.setLineWidth(lineWidth);
attachChild(line);
x1 = x2; y1 = y2;
x2 = 0; y2 = pSize/2; // Done
line = new Line(x1, y1, x2, y2);
line.setLineWidth(lineWidth);
attachChild(line);
touchableArea = new Rectangle(pSize/4, pSize/4, pSize * .75f, pSize * .75f);
touchableArea.setAlpha(0);
attachChild(touchableArea);
}
这样做将需要只是一个小几何/三角多。六角形顶点处的角度都是360/3度或120度。有了这些信息和使用Java数学库方法(尽管要小心将度数改为弧度),您应该可以在不使用其他代码的情况下轻松绘制这些数据。在将代码提交给IDE之前,首先在纸上使用图表。我觉得最好把六边形看作六个等边三角形,但是尽可能为你做最合适的做法。如果您遇到困难,请返回您的代码,我们将非常乐意提供帮助! –
我不知道是什么在链接的家伙在说什么,但基本的三角会告诉你,六边形,S侧,由S与它的高度*平方的3根或Java的单曲* Math.sqrt(3);' –
参见如何找到邻居这篇文章http://stackoverflow.com/questions/6661169/finding-adjacent-neighbors-on-a-hexagonal-grid – Buhb