Jump to content
  • Advertisement
Sign in to follow this  
juggerp

Storing Hex Tiles in a .png Tileset

This topic is 3337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey Everyone, I just have a question regarding the best way to store multiple hex tiles as a tileset in a .png file. Is it better to store the hexagons in a hexagonal grid or should hexagon tiles be stored in a rectangular grid (including transparent spaces in the areas surrounding the hexagon inside the rectangle)? It seems to me that it makes more sense to store in a rectangular grid and then just access the image at the correct x,y locations. However, based on the size of the hexagons that I am creating, the rectangle that the hexagon would fit in does not have nice dimensions i.e. there are decimal places attached to the height of each rectangle. The width of the hexagon is 80 pixels and based on some calculations, the height is approximates 92.4 pixels. However, unless I am mistaken (very possible!), the drawings that I make in photoshop only go to the nearest pixel, so I wind up creating a containing rectangle of 80 x 93. I guess basically I am just asking how anybody else has handled storing their hexagon tiles in file images as I am not sure I am handling it the best way.

Share this post


Link to post
Share on other sites
Advertisement
It'd probably be a good idea to stop worrying about making your hexagons mathamatically perfect and just make them 80x92.

Share this post


Link to post
Share on other sites
Unless you'll have an obscene number of large tiles (thereby having large memory consumption), it's way simpler just storing the hexagons as rectangles (getting the transparent areas by colorkeying, masking or alpha blending).

Share this post


Link to post
Share on other sites
Hello juggerp,

I'm currently also working on a 2D turn based hex strategy game from time to time (just for fun, it will very probably never be finished). All my tile graphics are arranged in a rectangular grid in one PNG image, and the pixels outside of the hexagons are simply left transparent. I'm using SFML for graphics output, which supports the PNG alpha channel. This way, drawing the map is really easy. I can even use semi-transparency at the tile borders to get nice transitions between the tiles. In most situations, it looks really good for such a simple solution, much better than I had expected before I tried it.

Share this post


Link to post
Share on other sites
There's what is essentially an updated version of the gamedev article here http://www.ziggyware.com/readarticle.php?article_id=278 that has a better description of the math, and simpler code.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!