Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to create a game environment that supports a 2D map. This is a really basic map, but must be split along lines that are not necessarily straight. So imagine a country with county boundaries. I then want to be able to detect drag / drop events within these counties.

What I'm really looking for here is a pointer to where to start on this (how it has been done before - any existing libraries out there), as I'm sure that what I'm trying to do is not new - although I can't find a beginners guide for this anywhere.

share|improve this question
up vote 7 down vote accepted

There are two general approaches I would take.

1) The polygon-based approach. Each of your zones is defined as a series of points. You can then do point-in-polygon testing for whether or not your cursor position is inside a given area. You can also do things like tessellate it and draw an image on it.

2) The image-based approach. Author an image where a specific pixel color represents a certain area. Kind of like how this question does. Then you do a check in the image pixel data for what color you're currently selecting to determine which zone you're in.

share|improve this answer

Amit Patel has some great information on polygonal map generation here:

He uses random points and generates a Voronoi diagram from those, and from there you can coalesce adjacent polygons to form county boundaries. Each of the original polygons is convex so checking a mouse click within them is fairly simple.

share|improve this answer
+1 for the wicked link. – Jastill Feb 3 '13 at 23:43

Your Answer


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.