Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm trying to create a basic grid of hex tiles. I found some code...

s=h/Math.cos(30*Math.PI/180)/2;
tile._x=x*s*1.5;
tile._y=y*h+(x%2)*h/2;

That does just that, but I think it's setup for hex's that have same length sides. However my hex has different length sides. It's width is 140 and it's height is 80. How would I change that code to accomodate that?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Try this: if w,h are the width and height of your tile image, replace the first two lines of that code sample with just

tile._x = x * 0.75 * w;

The factor of 0.75 comes from the geometry of hexagons, where the spacing between adjacent columns is 3/4 of the diameter of a single hexagon. (It's the same origin as the 1.5 in the original code, where s was the side length of the hexagon, which is half its diameter.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.