CCPhysicsShape Class Reference
| 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
-
+ circleShapeWithRadius:center: -
+ rectShape:cornerRadius: -
+ pillShapeFrom:to:cornerRadius: -
+ polygonShapeWithPoints:count:cornerRadius:
Accessing Basic Shape Attributes
-
massproperty -
areaproperty -
densityproperty -
frictionproperty -
elasticityproperty -
surfaceVelocityproperty
Accessing Collision and Contact Attributes
-
sensorproperty -
collisionGroupproperty -
collisionTypeproperty -
collisionCategoriesproperty -
collisionMaskproperty
Accessing Misc Attributes
-
nodeproperty
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 areaDeclared In
CCPhysicsShape.hcollisionCategories
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 *collisionCategoriesDeclared In
CCPhysicsShape.hcollisionGroup
The shape’s collisionGroup, if two physics bodies share the same group id, they don’t collide. Defaults to nil.
@property (nonatomic, assign) id collisionGroupDeclared In
CCPhysicsShape.hcollisionMask
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 *collisionMaskDeclared In
CCPhysicsShape.hcollisionType
A string that identifies the collision pair delegate method that should be called. Default value is @“default”.
@property (nonatomic, copy) NSString *collisionTypeDeclared In
CCPhysicsShape.hdensity
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 densityDeclared In
CCPhysicsShape.helasticity
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 elasticityDeclared In
CCPhysicsShape.hfriction
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 frictionDeclared In
CCPhysicsShape.hmass
Mass of the physics shape.
@property (nonatomic, assign) CGFloat massDeclared In
CCPhysicsShape.hnode
The CCNode to which this physics shape is attached.
@property (nonatomic, readonly) CCNode *nodeDeclared In
CCPhysicsShape.hsensor
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 sensorDeclared In
CCPhysicsShape.hsurfaceVelocity
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 surfaceVelocityDeclared In
CCPhysicsShape.hClass Methods
circleShapeWithRadius:center:
Creates and retuns a circular physics shape using the circle radius and center values specified.
+ (CCPhysicsShape *)circleShapeWithRadius:(CGFloat)radius center:(CGPoint)centerParameters
- radius
Circle radius.
- center
Circle center point.
Return Value
The CCPhysicsShape Object.
Declared In
CCPhysicsShape.hpillShapeFrom: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)cornerRadiusParameters
- from
Start point.
- to
End point.
- cornerRadius
Corner radius.
Return Value
The CCPhysicsShape Object.
Declared In
CCPhysicsShape.hpolygonShapeWithPoints: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)cornerRadiusParameters
- points
Points array pointer.
- count
Points count.
- cornerRadius
Corner radius.
Return Value
The CCPhysicsShape Object.
Declared In
CCPhysicsShape.h