Hi.
I would like to ask for help with making draggable sprites.
I'm making a card game and I would like to allow the player to drag the cards around and place them anywhere even on the top of other cards.
My problem is, if I place a card on the top of an other one, later when I try to drag the card most of the times it drags the card from the bottom and I would like to avoid that.
I would like to make it like if the pointer is over multiple cards, always drag the one on the top. What I was trying to do is using different depth for the card placed on the top of an other and I try to loop through each card and check the depth. If the pointer is over multiple cards then drag the one with lower depth (the one on the top), but because the loop going through the cards in order 1 to last it solves the problem only if I place the first card on the top of the second or the second on the top of the third and so on. It doesn't work the other way around because the loop always start with the first card and always pick the first card meet the condition (pointer is over the card and pointer is down) and never the second.
Most engines I was using before always had an option to "make sprite draggable" that solved this functionality for me, this is the first time I'm trying to make this on my own and I run out of ideas how to do it.
I know it a lot to ask, but anyone may have a working dragging code that willing to share or the idea how it supposed to be done?
Any help would be great.
Thanks.