Drag and Drop for multiple objects / display group

Thanks for the responses.

I can see there is going to be a problem however.  I would like to suggest you start with something simpler than this card game.

The mechanics you describe are quite difficult to code in an elegant and error free fashion.  I know it ‘looks simple’, but trust me, it is not.  This is not a beginner game.

The whole “drag a card” to an arbitrary hot-spot that changes based on how many cards are present in a stack/set, and the concept of dragging a set or stack of cards where the number of grouped cards can change… is way beyond beginner stuff.

(Individually, these mechanics are not rocket science, but combining them into an actual game, and accounting for weird user actions and interactions (aka corner-cases), that is the trick.)

While I want to help you, there are fundamentals here that need to be addressed / taught / learned first.

I will be doing at least one card game in my ‘Fundamentals Series’, but it won’t be solitaire (too hard to explain and code in such a way that users can grok it).  So, the best I can do is say:

Sorry!

Final note.  SSK2 would help with this, because believe it or not there will be vector math involved.  A good (in my opinion) solution will also involve the use of user defined Runtime events.  Of course there is dragging-and-dropping (that is part of the title).  The list goes on.

Please note: SSK2 is most useful for people with a solid understanding of the fundamentals. It is, in a sense, a faster and shorter (coding wise) way to achieve what would typically require lots of coding. i.e. SSK2 is a collection of solutions to typical problems.   It isn’t a way to skip learning the fundamentals unfortunately.

Thank you for your answer.

I will take a look at SSK2 and your Fundamentals Series.

The thing is, i just need the drag and drop for the game, no other math or calculation. As i said, the game is working good, the only thing that i need is the multi drag and drop. Could this really be that complicated that i had to stop working on this game?

Im a programmer and i did a 2D corona SDK game in a group for the university so i have basic knowledge. 

I also have a solution to get all cards that should be draggen when clicked on one card that is in the back of the stack and i also put all these cards in a group, the collision detection with other hot spots also works as well as the positioning of the cards when dropped.

The only thing i need is to drag the group like it would be a single card or maybe a other solution, like a work around.

At the moment i touch a card and the eventListener is called, this listener builds the new display group and drags it. When i make a example with a whole display group that i drag, it works finde, also when i use the drag code for a single card but the comination in my code doesnt work. I build the group and drag the group instead of the single card and this causes the problem because the dragged group is not at the same position like the mouse cursor. I could imagine that i just need to set / change or add some values in the drag function and this would work well.

I’m saying the drag and drop functionality you describe isn’t simple to implement.  Sorry.

Dragging and dropping is easy, but morphing its behavior based on context is more difficult.

Can you describe this more precisely?
“the dragged group is not at the same position like the mouse cursor”
Is there some offset when you drag
Or the cards in the group do not move at all?

@a.jaks this is quite easy to implement if you think about it in a different way

I would suggest you have 7 display groups (representing each stack of cards).  Insert the cards in the order they would naturally stack and give each one an index, a colour and a value.  The first card would have index 1, the one on top of it index 2, etc.

Then implement a global touch handler that spans all the display groups.  On phase==“began” you would store which display group you have hit (i.e. which stack of cards) and the index, colour and value of the card that was hit.

To perform the multiple drag n drop it is now simply a case of iterating the objects in that display group and selecting all those with a higher index.  Drop the alpha a bit and add a fill effect to indicate to the user which cards have been selected.  You drag the first card and then manually adjust the x,y of all the linked cards in phase==“moved”.

The “can I drop logic” will be simply based on comparing the colour and value of the dragged card to top card in the display group you are now hovering over.  Maybe apply a new fill effect or add a green overlay?  On drop, remove the cards from one display group and insert into the new display group and index the new cards accordingly.

@Arteficio

the cards move but there are offset. This happens when i touch the card, not when i move the card / cards.

@adrianm

yeah thats what i already do. Every card has a position for the position in the current group it is in.

I already tried to move all linked cards while using a for loop and move all cards at the same time but the cards are offset then. I think the for loop causes this problem because its looping on every single frame and i think thats why the rest of the cards is offet :confused:

There will not be an offset if you move each dragged card by the delta x,y of the first cards movement.  If card 1 moves 10,10 and you move each card also by 10,10 then they will always stay in the same position relative to each other.

You do not need a drag group.  Cards only leave the group (card stack) they were in when you insert them into their new group.

I do a similar thing in my game with dragged objects where my UI stays locked to the dragged object even thought the elements (being dragged) are all in different layers. 

@adrianm

thanks! it worked!!!

As i said, i tried this befor but i made a mistake and now i did it right so everything works fine!

And in my opinion its the best solution, because i dont need to make a seperate display group and insert all the object multiple times :slight_smile:

Thank you so much! I was about to give up this project / game but you showed me that there is a easy solution for this :wink: