Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

Peter Fisla

Drawing hex map

This topic is 6914 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

Hi all, I was wondering what would be the reasonable way to draw hexes. I''m working on a operational wargame, I have a structure that knows the coordinates of all the exes on the map. I have my transparency function set up so that I can draw my hex map. In ::OnDraw() which in WinApi really means WM_PAINT I have a for loop and I draw all my hexes (meaning the for loop uses the coordinate numbers from the strucutre). My map is 151 x 81 hexes big so the for loop is from 0 to 12392. Now I know this is not a good way to draw since I''m drawing all the exes even thouse not needed on the screen. So the trick is to draw only the hexes that my screen is currently displaying. I suppose one way it would be to check scroll bars and to find out what position they are and based on that draw the required hexes. This all still however pretty scetchy for my right now. Anyone have any idea ? Thanks for your help Peter

Share this post

Link to post
Share on other sites
essentially, this is what you need to do:

A) detect which hex the upper left corner of the view area is on.

B) draw a row of tiles (pick a number that is guaranteed to span the width of the view area.. having one or two extra wont hurt, but having too many will)

C) from the beginning of that row, move down a row, alternately moving SW then SE for even/odd rows, and continue drawing rows of tiles until you have drawn as many rows as will fit. again, having one or two extra rows wont hurt, when compared to redrawing the entire map.

Share this post

Link to post
Share on other sites

  • 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!