1
\$\begingroup\$

I'm working on a 2d card game for iOS and using Cocos2d. When a player picks up a card and drags it I would like to make it appear that the card is lifted off the table and dangling just below their finger. So when they move their figure the card is slightly delayed an looks like its being dragged in a fluid animation. When the player stops moving the card sort of bounces or sways for a second.

I've been trying to find someplace that does this but I can't come up with anything so I'm wondering is it even possible in a 2d environment? How would I go about doing this, answers can be abstract, i.e. not cocos2d.

Thanks,

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

When a card is selected, give it a target position. Then calculate a velocity proportional to the distance from where the card currently is and where it is going (i.e. the position of the finger). Then move the card by that velocity. By virtue of this system, the card will zoom across the screen and slow down as it approaches the finger.

The above should get you started, and can then be extended with concepts of forces, deceleration and so on, which will let your cards "bounce" and "sway".

Google "motion tweening" or "easing equations" for concrete examples of the math.

http://www.gizma.com/easing/ is a phenomenal source.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .