tags:

views:

68

answers:

1

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?

+2  A: 

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.

Brad Larson
Thank You for your help, but how i can i get those effect in cocos2d framework.
MacDev
@MacDev - I have no idea (I've never worked with cocos2d myself), but I didn't realize you were limited to working withing cocos2d. I've updated your question to reflect this.
Brad Larson
Thank You dear..
MacDev