Tween an Object to an Array

**How do I tween an object to an array?

What is the expected result

In my card drawing game, I expect an object /card to tween to the last position of an array, placing a card next to the other cards in hand; this “tween to array” will simulate drawing a card.

What is the actual result

I am currently tweening to a position x,y, but I need something more dynamic to keep even spacing between cards in hand.

Thank you!

For me I will have a scene variable to keep tracking how long or size of my hand
for example if a card has 200px width
When I draw a card:

  1. tween from starting point to x = variable HandSize
  2. Add value of card’s width (200px) to my variable HandSize

When you delete / use a card:
Action: remove value of card width (200) from the HandSize variable

Here it’s dynamic now.

You could tween to #cards_in_hand * offset, 600, where

#cards_in_hand is the number of cards in the array, and
offset is the gap you want between two adjacent cards

In this example, when a card is removed from a row the ones on the right move automatically. Maybe it can help for what you want to do.

Hi Mr Men,

Is there a way to tween to an array with rows and columns?

The solutions shown so far just offset the row, but I have a 4 x 2 array of cards.

THank you!

There will be, it just depends on how you want to fill the cells of the array.

You could use the formula I gave in my previous post, but use different X & Y starting points in it. So it would become:

#cards_in_hand * offset + target_cell_position_x, 600 + target_cell_position_y