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; ...

Get Cocos2d for iPhone 1 Game Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.