Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Draggable sprites.

Author
Message
Zigi
15
Years of Service
User Offline
Joined: 5th Jul 2009
Location:
Posted: 18th Apr 2016 18:08 Edited at: 18th Apr 2016 18:14
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.
Paronamixxe
AGK Bronze Backer
12
Years of Service
User Offline
Joined: 10th Feb 2012
Location: Sweden
Posted: 18th Apr 2016 18:40
I am using draggable sprites in my current project - however not in the way you seem to be. You seem to already have the actual dragging part sorted out, and I think that your other problem could be solved by simply keeping a variable that stores the topmost card. Each time you place a new card on the pile (in other words let go of the LMB and MouseX and MouseY are in the boundaries) just update this variable.

Otherwise, if you don't have predetermined stacks I'm pretty sure that GetSpriteHit (X,Y) selects the sprite with the lowest depth.
From the command page:
Quote: "
Returns the ID of the first sprite found under the point x,y in world coordinates. 0 if none. Sprites are ordered by depth so a sprite appearing above another in the draw order will be returned instead of the sprite behind it.
"


Hope this helps.
cheers
Zigi
15
Years of Service
User Offline
Joined: 5th Jul 2009
Location:
Posted: 18th Apr 2016 20:11
GetSpriteHit() seems to solved the problem

Thanks a lot.
Paronamixxe
AGK Bronze Backer
12
Years of Service
User Offline
Joined: 10th Feb 2012
Location: Sweden
Posted: 19th Apr 2016 16:24
No problem! Glad to help.
cheers

Login to post a reply

Server time is: 2024-11-25 07:51:34
Your offset time is: 2024-11-25 07:51:34