Inherits from NSObject
Declared in CCPhysicsShape.h

Overview

Every CCPhysicsBody has at least one shape attached to it. Normally the shape is created for you when creating the body. If you wish to create a composite body that is composed of multiple shapes, you can create them yourself and then create the body from them. This gives you extra flexibility in designing a complex shape or setting up different physics properties on different parts of the body.

Another thing to keep in mind is that the collision detection of the underlying physics library (Chipmunk2D), is based around shapes and not bodies. CCPhysicsCollisionPairDelegate methods will be invoked based on specific shapes colliding and not the physics bodies or nodes that own them. Using simple shapes instead of composite ones can make collision handling code simpler depending on what you need to do.

Tasks

Creating a CCPhysicsShape Object

Accessing Basic Shape Attributes

Accessing Collision and Contact Attributes

Accessing Misc Attributes

Properties

area

Area of the shape in points2. Please note that this is relative to the CCPhysicsNode the shape is attached to, changing the node or a parent can change the area.

@property (nonatomic, readonly) CGFloat area

Declared In

CCPhysicsShape.h

collisionCategories

An array of NSString category names of which this shape is a member. Up to 32 unique categories can be used in a single physics node. A value of nil means that a shape exists in all possible collision categories. The deefault is nil.

@property (nonatomic, copy) NSArray *collisionCategories

Declared In

CCPhysicsShape.h

collisionGroup

The shape’s collisionGroup, if two physics bodies share the same group id, they don’t collide. Defaults to nil.

@property (nonatomic, assign) id collisionGroup

Declared In

CCPhysicsShape.h

collisionMask

An array of NSString category names that this shape wants to collide with. The categories/masks of both shapes must agree for a collision to occur. A value of nil means that this body will collide with a shape in any category. The default is nil.

@property (nonatomic, copy) NSArray *collisionMask

Declared In

CCPhysicsShape.h

collisionType

A string that identifies the collision pair delegate method that should be called. Default value is @“default”.

@property (nonatomic, copy) NSString *collisionType

Declared In

CCPhysicsShape.h

density

Density of the shape in 1/1000 units of mass per points2. The co-efficent is used to keep the mass of an object a reasonably small value. Note that mass and not density will remain constant if an object is rescaled.

@property (nonatomic, assign) CGFloat density

Declared In

CCPhysicsShape.h

elasticity

Elasticity of the physics shape. When two objects collide, their elasticity is multiplied together. The calculated value can be ovrriden in a CCCollisionPairDelegate pre-solve method. Defaults to 0.2.

@property (nonatomic, assign) CGFloat elasticity

Declared In

CCPhysicsShape.h

friction

Surface friction of the shape, when two objects collide, their friction is multiplied together. The calculated value can be overridden in a CCCollisionPairDelegate pre-solve method. Defaults to 0.7

@property (nonatomic, assign) CGFloat friction

Declared In

CCPhysicsShape.h

mass

Mass of the physics shape.

@property (nonatomic, assign) CGFloat mass

Declared In

CCPhysicsShape.h

node

The CCNode to which this physics shape is attached.

@property (nonatomic, readonly) CCNode *node

Declared In

CCPhysicsShape.h

sensor

Is this shape a sensor? A sensor will call a collision delegate but does not physically cause collisions between bodies. Defaults to NO

@property (nonatomic, assign) BOOL sensor

Declared In

CCPhysicsShape.h

surfaceVelocity

Velocity of the surface of a shape relative to it’s normal velocity. This is useful for modelling conver belts or the feet of a player’s avatar. The calculated surface velocity of two colliding shapes by default only affects their friction. The calculated value can be overriden in a CCCollisionPairDelegate pre-solve method. Defaults to CGPointZero.

@property (nonatomic, assign) CGPoint surfaceVelocity

Declared In

CCPhysicsShape.h

Class Methods

circleShapeWithRadius:center:

Creates and retuns a circular physics shape using the circle radius and center values specified.

+ (CCPhysicsShape *)circleShapeWithRadius:(CGFloat)radius center:(CGPoint)center

Parameters

radius

Circle radius.

center

Circle center point.

Return Value

The CCPhysicsShape Object.

Declared In

CCPhysicsShape.h

pillShapeFrom:to:cornerRadius:

Creates and returns a pill shaped physics shape with rounded corners that stretches from ‘start’ to ‘end’.

+ (CCPhysicsShape *)pillShapeFrom:(CGPoint)from to:(CGPoint)to cornerRadius:(CGFloat)cornerRadius

Parameters

from

Start point.

to

End point.

cornerRadius

Corner radius.

Return Value

The CCPhysicsShape Object.

Declared In

CCPhysicsShape.h

polygonShapeWithPoints:count:cornerRadius:

Creates and returns a convex polygon physics shape with rounded corners. If the points do not form a convex polygon then a convex hull will be created from them automatically.

+ (CCPhysicsShape *)polygonShapeWithPoints:(CGPoint *)points count:(NSUInteger)count cornerRadius:(CGFloat)cornerRadius

Parameters

points

Points array pointer.

count

Points count.

cornerRadius

Corner radius.

Return Value

The CCPhysicsShape Object.

Declared In

CCPhysicsShape.h

rectShape:cornerRadius:

Creates and returns a physics box shape with rounded corners.

+ (CCPhysicsShape *)rectShape:(CGRect)rect cornerRadius:(CGFloat)cornerRadius

Parameters

rect

Box dimensions.

cornerRadius

Corner radius.

Return Value

The CCPhysicsShape Object.

Declared In

CCPhysicsShape.h