Book Image

Mastering Cocos2d Game Development

By : Alex Ogorek
Book Image

Mastering Cocos2d Game Development

By: Alex Ogorek

Overview of this book

Table of Contents (15 chapters)
Mastering Cocos2d Game Development
About the Author
About the Reviewers

Creating movements on a Bézier curve

If you don't know what a Bézier curve is, it's basically a line that goes from point A to point B over a curve. Instead of being a straight line with two points, it uses a second set of points called control points that bend the line in a smooth way. When you want to apply movement with animations in Cocos2d, it's very tempting to queue up a bunch of MoveTo actions in a sequence. However, it's going to look a lot nicer ( in both the game and the code) if you use a smoother Bézier curve animation.

Here's a good example of what a Bézier curve looks like:

As you can see, the red line goes from point P0 to P3. However, the line is influenced in the direction of the control points, P1 and P2.

Examples of using a Bézier curve

Let's list a few examples where it would be a good choice to use a Bézier curve instead of just the regular MoveTo or MoveBy actions:

  • A character that will perform a jumping animation, for example, in Super Mario Bros

  • A boomerang as a weapon...