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 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
add comment

2 Answers

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
add comment

Amit Patel has some great information on polygonal map generation here: http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/

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
add comment

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.