Sign in to follow this  
s3r1n

Hexagon Tile Map

Recommended Posts

s3r1n    122
Hello, I'm trying to come up with the standard size of a hexagon in my hexagon tile map. I'm having extreme difficulty for some odd reason. Do most developers use irregular hexagons? If so, can anyone provide some information? So far, I can't come up with a way to use a perfect hexagon and provide pixel perfect placement (can only get whole numbers for either height or width, not both). Any help would be appreciated. Ryan

Share this post


Link to post
Share on other sites
SiCrane    11839
Isometric games with pixel perfect layouts generally use irregular hexagons, for a given value of "irregular". Let's say you have a width of 60 pixels for your hexagons, which would give you a triangular height of about 17.32 pixels. The visual difference between 17.32 and 17 pixels is very, very small.

Share this post


Link to post
Share on other sites
s3r1n    122
Is it then feasible to use a perfect hexagon, and when it comes time to apply the math, simply round the results when I go to display?

Share this post


Link to post
Share on other sites
s3r1n    122

// Here's my constants
#define PI 3.1415926535897932384626433832795

int SCREEN_WIDTH = 800;
int SCREEN_HEIGHT = 600;

int HEX_WIDTH = 128;
int HEX_HEIGHT = 110;
double HEX_SIDE = floor(HEX_HEIGHT / 2 / cos(30 * PI / 180));

// Here's my render loop
for (int x = 0, col = 0; x < SCREEN_WIDTH; col++, x = col * HEX_SIDE * 1.5) {
for (int y = 0, row = 0; y < SCREEN_HEIGHT; y += HEX_HEIGHT, row++) {
Render(x, row * HEX_HEIGHT + (col % 2) * HEX_HEIGHT / 2);
}
}


The code above seems to work.

Screenshot:


I just want to make this is the correct way to do this.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this