Jump to content
  • Advertisement
Sign in to follow this  
bioxx

Question about nonstandard UI shapes

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

I hope that the title accurately reflects what I have a question about. I'll attempt to explain it better here. Lets say that I have a flat map of the world like you might find in a geopolitical sim like superpower and I want to be able to have accurate selection of countries or regions. What kind of system would I use for this? I've tried brainstorming how this was accomplished in those titles, but I've just been coming up with ideas that would probably suffer from performance problems. I don't need a language specific answer, just some generalized advice if at all possible. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Probably the most straight-forward way to do it is to represent the region as a polygon-type shape. Draw a series of short line segments that approximately follow the curvature of the region you want to be selectable. Then use a simple point-in-polygon test algorithm to detect when the user interacts with that area.

Of course if you want to get crazy fancy you can start doing things like representing the edges with splines or other parametric curves, but straight lines are a lot easier and almost always sufficient. It may take a lot of tiny lines to get good-looking results for some shapes, but on a modern computer, you'd almost have to bend over backwards for that to be a problem.


Another option is to just use a bitmap-type mask. Draw the shape, then store a black-and-white copy someplace in memory. Black pixels are inside, white pixels are outside. This can be accomplished easily in most image editing software, for example. Then you just look at the mask pixel color to see if a point on the rendered image is "inside" or "outside."

If you have something like a world map, you can have each "country" be a different color in the hidden mask image, and use the color to determine which region in particular is "active."

Share this post


Link to post
Share on other sites
Thanks for the reply ApochPiQ, answers my question nicely. The mask idea is one thing that I'd come up with, but I had thought that it might be too memory intensive, but I did not think about just combining them all into one bitmap. Anyways thanks again!

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!