user547995
user547995

Reputation: 2085

Positioning of Polygons in Slick2D

I try to create hexagons and place them on the opengl window. 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:

enter image description here

The problem is that the row 2 should integrate under row 1.

Upvotes: 1

Views: 296

Answers (1)

mrVoid
mrVoid

Reputation: 995

The actual offset of the tile is not its size.

There is a great article on this here

Hex Grid dimensions

Upvotes: 2

Related Questions