O'Reilly logo

Cocos2d for iPhone 1 Game Development Cookbook by Nathan Burba

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

Dragging and collision filtering

In a previous recipe, we handled user input to allow the user to drag an object. In this example, we see a bowl filled with pieces of fruit that can be dragged across the screen. A piece of fruit does not collide with another piece of fruit.

Dragging and collision filtering

Getting ready

Please refer to the project RecipeCollection02 for full working code of this recipe.

How to do it...

Execute the following code:

enum { //Collision bits for filtering CB_GROUND = 1<<0, CB_FRUIT = 1<<2, CB_BOWL = 1<<4 }; @implementation Ch4_DraggingAndFiltering -(CCLayer*) runRecipe { [super runRecipe]; [message setString:@"Pick up the fruit."]; //Create level boundaries ...

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