How to recognize a click / touch to a state in an earth map?
I'm planning to build a game with an earth map.
What is the best way to recognize a click / touch to a state (e.g. USA, Germany)?
My idea is to fill all states with transparent squares / circles of different sizes, which a assigned to a state and recognize the click / touch. Are there better solutions?
Best Answers
-
Socks London, UK.Posts: 12,822
@RThurman's excellent Collision Detection For Odd Shapes comes to mind.
It's about half way down this page:
https://forums.gamesalad.com/discussion/52494/spare-code-dump-it-here/p14 -
Socks London, UK.Posts: 12,822
@ThoPel said:
NipaDidIt Perhaps it is easier to work with a table, something likePixelX,PixelY,State
1,1,USA
1,2,USA
1,3,USA
...But with a display solution of 768x1024 for iPad, I will require 786.432 rows less all water areas.
You would only need to go on a pixel by pixel basis around non-regular shapes, the vast inland part of most states could be one giant rectangle.
Answers
The method you explained is how i would do it.
I don´t think there´s a better way without custom collision shapes, and that´s not available (yet).
Mental Donkey Games
Website - Facebook - Twitter
@NipaDidIt Perhaps it is easier to work with a table, something like
PixelX,PixelY,State
1,1,USA
1,2,USA
1,3,USA
...
But with a display solution of 768x1024 for iPad, I will require 786.432 rows less all water areas.
I would work with invisible image/buttons on top of the map too. Not the table method you've suggested.
@Socks Okay, if I understand @RThurman's solution right, I need straight lines. But borders are sometimes a little bit zigzag :-)
Yes, you right.
Zigzags are a series of straight lines.
I think RThurman's solution is a little more complicated than 'draw some straight lines to define the area' - from what I understand the shape has to be convex (no interior angles greater than 180°) but maybe @ RThurman can explain it a little more, but even here all you'd need to do is to split the state up into more managable convex shapes.
Also, I think you could also do this with simple rectangles that loosely define the areas, I don't think you should spend a lot of time trying to accommodate people who, when selecting a state, click right on the boarder with another state, to the degree than you need to go down to the pixel level to discern which state they have selected, most (sane) people will click in the middle of a state to select, if you are clicking right on the boarder and accidentally selecting the wrong state, and then loudly tutting, you don't deserve to use the app