O'Reilly logo

Cocos2d Cross-Platform Game Development Cookbook - Second Edition by Siddharth Shekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Looking at different body types

Let's look at other body types.

Getting started

Nothing additional needs to be done here.

How to do it…

Now that you understand what a static body does, let's change the type of the body to dynamic and see what it does.

We will change the body type to dynamic by changing the body.type variable to dynamic, as follows:

body.type = CCPhysicsBodyTypeDynamic;

Now, we will run the game again. You will see that now the circle is green in color, and it falls through the bottom of the screen. The pink color signifies that it is a dynamic body.

Note

If you don't see anything on the screen, make sure you have set the debugDraw variable to true again in the init function.

However, how do you stop it from going offscreen? This is done ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required