# Understanding hexagonal tiles

You should already know Tile Maps: they are often used for the level design in two-dimensional games.

The most used (and simplest) tiling system has squares. Tileball is an example of a game made with this method.

Even if there are a lot of games using this tiling system, it’s easy to find its limit. All movements are restricted to four directions: up, down, left, right.

Some more complex games require a more complex tiling system.

That’s why I am introducing you the hexagon based tile system (hex maps from now on)

Wkipedia explains us the advantage of a hex map over a square grid map is that the distance between the center of each hex cell and the center of all six adjacent hex cells remains constant. Compare this to a square grid map where the distance from the center of each square cell (of side length x) to the center of its four diagonal adjacent cells is longer than the distance to the center of its four cardinal adjacent cells (xâˆš2 instead of x).

It’s nothing new, because you may find hex maps in Gettysburg, a board game released in 1958 (yes: half a century ago), as you can see in the photo showing the 125th Anniversary Edition of the game

Back to computer games, you can play The Battle for Wesnoth, a free turn based strategy game designed in June 2003 by David White using hex maps

Now that we know hex maps are important, let’s see what is an hexagon: in geometry, a hexagon is a polygon with six edges and six vertices. When the six sides of an hexagon have the same length, we are talking about a regular hexagon.

Regular hexagon properties

As you can see, if all sides have the same lenght, we can say the total length of the hexagon is:

`Total length = Side + 2*(Side*sin(30Â°)) = Side + 2*0.5 = 2*Side`

And the total height is:

`Total height = 2*(Side*cos(60Â°))`

Now, it’s important to know we can tile hexagons in two ways: I don’t think someone already gave a name to the ways you can tile hexagons, so I will call H-hex map a map made tiling hexagons horizontally and V-hex map a map made tiling hexagons vertically, just like in the picture.

Obviously, each map has its own way to manage tiles.

And that’s all… obviously I am about to code everything in Actionscript, meanwhile if you have some code to share, show the world you are awesome

• interesting concept

• Jack Hopkisn

exellent! Perfect timing as always as i am currently struggling with it ;)

• JDog

This is great, will this be added to the Boxhead game tutorials ? Since boxhead has 8 directions of movement, 6 is close.

• JDog, the 8 and 6 directions are very different. the tiles used in the boxhead games are not hex tiles and therefore do not have the difficulties that come with placing them.
what you are talking about is walking directions, that is a whole different topic :)

• JDog

Oh heck, I knew that, I was just wondering. Its isometric isn’t it….sorry I was being silly. An isometric tile engine would be cool…

• Olivier

I not to long ago made hexagons tile (tho with as2) for a flash website, i’d like to see how you do this, i wrote a very simple function which drew horizontal lines of hexagons, and per line the starting position jumped left or right half a hexagon. Im sure there are better mathematical ways, enlighten me :)

• JDog

Emanuele you forgot about Hexic, the best game in the world to feature Hexagons !

• Pingback: Odds & Ends: April 17, 2008()

• Your hexagon diagram is wrong.
Side * cos(60) should be Side * cos(30) or Side * sin(60) I think (:

Thx for the excellent tutorials btw.

• xklamatok

another way to figure out the height of a hexagon (V-Hex style as per your example):
Pythagoras sez:
a^2 + b^2 = c^2
we know c which is the radius and a which is half the radius.
So we are looking for sqrt(c^2 – a^2) or sqrt(3/4)*radius.
i guess one of them might be faster, like a 2.345 milliseconds :D

• About 10 years ago, I wrote a collection of functions that would help a person navigate hex maps. The functions included: Identifying the adjacent hexes, identifying the shortest path between two hexes, the relative position of a hex from the perspective of another hex and the distance between two hexes.

Let me see if I can find that code and I will send it to you.

• Pingback: Halloween Couples : Emanuele Feronato()

• Your stuff on hexagons is interesting. Maybe you will like the way that I have used the concept for my Hexidek. If you google the word, you ought to find some pics online.

• B

Your formula in the hexagon diagram is slightly off. The longer side of the right triangle should be “side” x sin60, OR “side” x cos30. Nice work otherwise!!

• Nice work. Thanks for the concept explanation.