简体   繁体   English

在Slick2D中多边形的定位

[英]Positioning of Polygons in Slick2D

I try to create hexagons and place them on the opengl window. 我尝试创建六边形并将其放置在opengl窗口中。 I want to use them as a tiled-map. 我想将它们用作平铺地图。 My current code looks like this: 我当前的代码如下所示:

private Polygon generateTile(){
        Polygon poly = new Polygon();
        for(int i = 0; i < 6; ++i) {
            poly.addPoint((float)Math.sin(i/6.0*2*Math.PI),
                    (float)Math.cos(i/6.0*2*Math.PI));
        }
        return poly;
    }

private void generateTiles (){
        Shape s;
        Polygon p = generateTile();
        for (int i = 0; i <= 2; i++) {
            for (int j = 0; j <=10; j++) {
                s=p.transform(Transform.createScaleTransform(Constants.TILE_SIZE, Constants.TILE_SIZE));
                if (i%2==0) {
                    s.setLocation(s.getMaxX()*j*2, s.getMaxY()*i*2);
                } else {
                    s.setLocation(s.getMaxX()*j*2+Constants.TILE_SIZE, s.getMaxY()*i*2);
                }

                tiles.add(s);

            }
        }

Window: 窗口:

在此处输入图片说明

The problem is that the row 2 should integrate under row 1. 问题在于,第2行应整合到第1行之下。

The actual offset of the tile is not its size. 瓦片的实际偏移量不是其大小。

There is a great article on this here 在灯架上有一个伟大的文章在这里

六角格尺寸

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM