Book Image

Learning Cocos2d-JS Game Development

By : Emanuele Feronato
Book Image

Learning Cocos2d-JS Game Development

By: Emanuele Feronato

Overview of this book

Table of Contents (18 chapters)
Learning Cocos2d-JS Game Development
Credits
Foreword
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
9
Creating Your Own Blockbuster Game – A Complete Match 3 Game
Index

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 with the mouse/finger...