Chapter 5. Let's Get Physical!

For our fifth game, we will get down to the physics of things. Cocos2d-x comes bundled with two wonderful physics engines: Box2D and Chipmunk. In this chapter, we will make use of the versatile and robust Box2D physics engine to add some realism to our game.

In this chapter, you'll learn about the following:

  • Box2D basics
  • Setting up Box2D world and debug draw
  • Creating Box2D bodies, fixtures, and shapes
  • Manipulating simple physics at runtime
  • Maintaining a state machine
  • Listening for collisions
  • Creating pools for reusable objects

An overview of Jumpy Clown

Our first physics game stars a clown that has a dream to reach the sky. Naturally, gravity pulls him down each time he jumps and so he needs our help. We need to build trampolines for him as he begins to fall, enabling to him reach as high as possible. We can build him a trampoline simply by sliding our finger across the screen. Every now and then, our clown runs into a bottle rocket that shoots him further upwards and a balloon which takes him steadily higher.

This is what we will achieve by the end of this chapter:

An overview of Jumpy Clown
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.183.10