Animate a control node to the end of an HBoxContainer

Godot Version

v4.2.1.stable.official [b09f793f5]

Question

I am making a deckbuilder game. In games like slay the spire or balatro, when new cards are added to your hand the cards in your hand move to the side and the new cards get added to the end of the hand. I am attempting to replicate this with an HBoxContainer. Is there a way to determine where the end of the container will be, then use a tween to animate the new card into the correct place from a draw pile located elsewhere? I tried instantiating the scene for my card (control node) under the draw pile UI then tween it to the container. I did this by adding a “spacer” (invisible control node) the size of a card then animating the new card to the location of the spacer. This caused the new card to animate to the top corner of the screen instead. Has anyone done something like this in their game and can share how it was accomplished?

The end of the container is global_position+ size. Is that what you’re looking for?

I should have specified, I want the location of where the next item in the container would be when adding a new object. I can try animating it to the end of the entire container node but that might be a little choppy depending on container size

Make it visible but set it’s modulate.a to 0. Making it visible means the HBox will make room for it. Then tween it visible again. You now know where it will be because it is already there, just invisible.

Or, depending how your cards are made, you can tween the y scale to make it taller and taller until it reaches it’s full height, then tween it visible. This will move all the items above slowly up instead of just jumping up.

Or, you could make the space as above, but then tween in the card from offscreen into its original position. Just make a note of the original position of the card (which is a child of the placeholder) to use in the tween.

There are so many ways to do this, and so many affects you could use, it is really impossible to list them all. Hope this helps in some way of gives you some ideas.