I’m making a card game, and I’ve added the cards to the game. All cards are the same object, and I’ve assigned each card an ID with variables. When there are 4 cards in hand, I want to click on the 2nd card to trigger an animation change for the 3rd card to the 2nd, the 4th card to the 3rd, and then hide the 4th card. How can I do this?
Do you want to move the cards across to the left and cover the one that was clicked?
Your way could be nice too, but it seems too complicated for me to do.
Not really, it’s a fairly straight forward process. Add the tween behaviour to the card objects, and then add events like:
[edited - took out the unnecessary trigger once]
Is there a chance you could explain in a bit more detail, or could you share part of the project?
Sure. From the events in my screen snip above:
- The first event declares a local variable, so it can only be accessed by the event it’s declared in and that event’s children.
- The first event also selects the card under the mouse cursor when the left mouse button has been released.
- The local variable it assigned the Id of the card that has just been clicked. The opacity of the clicked card is tweened (changed over time) to invisible over 2 seconds, and when that’s done the card is deleted.
- The subevent then selects all the card objects. This is because before this only the clicked card was in the list of card objects for GDevelop to work with.
- The selection of all cards is filtered to those that don’t have the same id as the one clicked (i;e pick all the cards other than the one clicked), and from that subset, only select the cards on the right of the clicked card. This is done with the card’s X position being compared to the cursor’s X position.
- Those cards that have been selected (all those to the right of the clicked card) are moved across by 1 card object width to the left from each card’s current X position. You may need to change the amount you subtract from the current X position if the cards overlap or there is a gam between the cards.
HTH