MacDev
MacDev

Reputation: 25

How do I create a stick bending effect in cocos2d?

I would like to bend sticks in an animated fashion in my cocos2d application in response to user touches. A good example of this is a diving board in a swimming pool when a person jumps from the board into the pool. How would you create the animation of the diving board bending up and down?

Upvotes: 0

Views: 633

Answers (1)

Brad Larson
Brad Larson

Reputation: 170317

I would recommend using a CAShapeLayer for this. CAShapeLayers let you animate between different defined paths with the same number of control points. In this case, you could create a path for the straight condition using a series of Bezier curves that aren't curved, and then draw a path with curves for the bent condition.

Using a CABasicAnimation, you could animate between these two states smoothly, creating the effect you want. You could even use a CAKeyframeAnimation to create a little bounce in the animation between straight and bent.

For more on CAShapeLayer, I direct you to the article "Marching Ants With Core Animation" by Matt Long and "Complex Interpolation with CAShapeLayer (Free)" by Joe Ricioppo.

Upvotes: 3

Related Questions