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

Using different shapes

The primary attribute a Box2D body has is its shape. Box2D uses two classes, b2PolygonShape and b2CircleShape, to represent any possible shape. In this recipe, we will create a number of different shapes.

Using different shapes

Getting ready

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

How to do it...

Execute the following code:

@implementation Ch4_DifferentShapes /* Here add an object randomly chosen from a rectangle, square, circle, convex polygon and multi-fixture concave polygon. */ -(void) addNewObjectWithCoords:(CGPoint)p { //Initialize the object GameMisc *obj = [[GameMisc alloc] init]; obj.gameArea = self; ...

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