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?
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.
精彩评论