Chapter 7. Adding Physics to Your Games Using the Box2D Engine
If you ask me what the biggest revolution in casual gaming is, no doubt I'll say physics engines. A lot of top-selling casual games such as Crayon Physics, Totem Destroyer, Crush the Castle, Angry Birds, Tiny Wings, just to mention a few use physics engines to add a realistic behavior that wouldn't be possible without such engines.
The most popular among physics engines in the 2D world is Box2D, initially written in C++, then ported to all major languages, including JavaScript.
Cocos2d-JS supports Box2D, and this chapter will cover the creation of a physics game, including these concepts:
- Configuring and setting up Cocos2d-JS to add the Box2D engine to your games
- Creating a physics world
- Giving the world a realistic gravity
- Combining bodies, shapes, and fixtures to create a physics object
- Creating a material
- Creating static objects
- Creating dynamic objects
- Attaching sprites to physics objects
- Selecting physics objects...