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

Creating composite bodies

We also need to create a basket that can carry gifts and ornaments. Let's take a look at how to create a composite body so that we can open the top of the box and create a side and a bottom for the basket.

A composite body is a collection's physicsBody that is clubbed together to create a new body.

Getting started

Import basket.png for this section. This is all you will need.

How to do it…

Until now, we have used standard body shapes, such as circles and rectangles. To create a composite body, we can create individual shapes and attach them to the body. Let's take a look at how it is done.

Create a new function called addBasket and add the following code into it. Also, create a global CCSprite variable called basketSprite

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