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

Changing body properties

Each body or shape has certain body properties, such as mass, friction, bounciness, and so on, just like any physical body in nature. Let's take a look at how we can modify these values.

Getting started

There is no additional work to be done here.

How to do it…

For regular bodies that don't have a specific shape attached to them, we will add mass, friction, and bounciness by changing the values of the mass, friction, and elasticity properties of the object.

For the gift body, after creating it, we will add the following lines of code:

  CCPhysicsBody *giftBody  = [CCPhysicsBody
    bodyWithRect:(CGRect){CGPointZero,
    giftSprite.contentSize} cornerRadius:0];

  giftBody.mass = 1.0f;
  giftBody.friction = 0.2f;
 giftBody.elasticity = 0.0f; ...

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