I'm trying to draw a map with hexagonal tiles. However, I'm struggling to get the tiles to line up properly, so there is no space inbetween them. One with the tiles I use normally and one zoomed in on with another tile made to make sure it's not just the antialiasing playing tricks on me.
This is the code that's responsible to get the pixel coordinates for every tile. Apparently there's some miscalculation with the offset of every odd row, but simply adding or subtracting a pixel only increases the gaps.
private static final float HEX_WIDTH = 97; // 139 for colored tiles
private static final float HEX_HEIGHT = (float) (Math.sqrt(3)/2 * HEX_WIDTH);
public Vector2 getHexCoordinates(Hexagon hex) {
float x = (float) HEX_WIDTH * hex.getGridX() * 3 / 4;
float y = (float) HEX_HEIGHT * (hex.getGridX() / 2 + hex.getGridY());
y = (hex.getGridX() % 2 == 0) ? y : y + HEX_HEIGHT / 2;
return new Vector2(x, y);
}
In addition here's the tiles I'm using in case anyone is wondering.
Scaling the individual Sprites by 1.01f reduced the size of the gaps enough to consider this problem solved.