A way to create a simple game GUI

I managed to find a lot of information about the real development of logic for games. I would really like to make a card game, but I just don’t understand how to select an object (or at least the correct path) based on the position of the mouse. At first I thought about checking the bounding box, but not all of my bitmaps are rectangles. Then I thought that I create a hidden buffer, each of which has a different color, but it seems ridiculous to do it this way. I wonder how this is done. For example, how does Adobe Flash know the object under the mouse?

thanks

+6
c ++ user-interface
source share
2 answers

Your question is how to determine if the mouse is above a non-rectangular bitmap. I assume that all your bitmaps are really rectangular, but they have transparent areas. You should already somehow determine which part of your (rectangular) bitmap is transparent, depending on the scheme you use (for example, if you designate the color as transparent or use a bit mask). You will also recognize the z-order (layering) of bitmaps on your canvas. Then, when you detect a click at position (x, y), you need to find a list of rectangular bitmaps that span that pixel. Sort them in z-order and for each check if the pixel is transparent or not. If yes, go to the next bitmap. If not, then this is the selected bitmap.

+6
source share

Or you can use a geometric solution. You must store / manage the map / item geometry. For example, a list of shapes, such as circles, rectangles.

Perhaps triangles or ellipses if you have a lot of time. Saying that a triangle has a point or not is a mathematical issue and can be numerically unstable if the triangle is very thin (the algorithm has division). . Fix: How to determine if a point is in a two-dimensional triangle?

I voted for abc.

+1
source share

All Articles