Mouse over visible portion of Sprite (stacked sprites)


I am developing a card game and I wish to detect when the mouse is over the player’s cards.

My question is: how do I detect when the mouse is over the visible part of each card, since they are all partially stacked on top of each other?


I am inclined to follow the logic:

1- if the card is NOT the top-most one, then set it “virtual bounds” as a small rectangle (the visible part of the card).
2- if the card is the top-most one (7-clubs in my example) then the full card-size rectangle is the area to check for mouse over.

Does that makes sense or there is another easier way of doing this?


why not give your actual bounding rectangles a z-component as well, and sort them like you are sorting it for rendering.

you now just order the bounding-rectangles by z and return the first you find a hit.


Awesome! That makes sense. Thanks!!