Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.


+24 votes

Does anyone have some advice on making and placing hex tiles? What are some ideas for aligning them on the map? What resources have you found for working with/creating hex tiles in jfx?

asked in CSC305 Fall 2022 by (1 point)

3 Answers

+14 votes
Best answer

For creating the tiles, I would use gc.fillPolygon() if a canvas is being used, or a 6-sided polygon object as Matteo put if a grid is being used.

When making a grid out of hexagons, there will be two 'types' of rows. This is simply because of the way the math works out with the hexagons. One offset to the left, and another offset to the right, for an example to help imagine this I would look at floor tiles


So now that you have the two rows you can just offset the one row by whatever X value and then the tiles should fit nicely into the gaps created by the first row, then just alternate the types of rows. We haven't implemented this feature yet, but this is how I imagine would be the easiest way to do it.

answered by (2.4k points)
selected by

This is super helpful! I didn't even think of having hexes being on separate, offset rows.

+12 votes

Making hex tiles should be as easy as creating 6-sided Polygon objects in scenebuilder. Placing them requires some math, but basically, you want each side of the hex tile to line up exactly with the side of another hex tile, so each has exactly six neighbors.

answered by (1 point)
+12 votes

It is similar to creating tiles, just requires some math on making sure the x and y coordinate of each hex is placed correctly. However, a possible issue may be how the user wants the hex's aligned. For example they may want a hexagon of the hex tiles or a square shape of the hex tiles. Again, I think it may require some time to align the hex tiles neatly.

answered by (2k points)