# CCPhysicsNode Class Reference

Inherits from | CCNode : CCResponder : NSObject
Declared in | CCPhysicsNode.h

## Overview

A CCNode that enables physics simulation in it’s children. To use CCPhysics, you create a physics node, and then attach CCPhysicsBody objects to any child node that you want to have gravity or collisions applied to. Physics nodes are also where you set up a delegate object that can tell you about collision events. Lastly, you can query for physics objects near a point, along a ray, or within a certain bounding box.

### Units:

For simplicity, CCPhysics does not use SI units, and the performance is not tuned to any particular scale. Positions and distances are expressed in regular Cocos2D points relative to whatever node is most relevant. For example, positions are in the same coordinates as the physics node. Shapes and joint anchors use the local coordinates of the node their body is attached to so that they properly respect it’s transform. Mass has no particular units. I personally find it intuitive to use 1.0 as the main player’s mass and set everything else based on that. Time is expressed in seconds.

## Tasks

- `debugDraw` property
- `gravity` property
- `iterations` property
- `sleepTimeThreshold` property
- `collisionDelegate` property
- `– pointQueryAt:within:block:`
- `– rayQueryFirstFrom:to:block:`
- `– rectQuery:block:`

## Properties

### collisionDelegate

The delegate that is called when two physics bodies collide.

`@property (nonatomic, assign) NSObject<CCPhysicsCollisionDelegate> *collisionDelegate`

#### Declared In

`CCPhysicsNode.h`

### debugDraw

Should the node draw a debug overlay of the joints and collision shapes? Defaults to NO.

`@property (nonatomic, assign) BOOL debugDraw`

#### Declared In

`CCPhysicsNode.h`

### gravity

Gravity applied to the dynamic bodies in the world. Defaults to CGPointZero.

`@property (nonatomic, assign) CGPoint gravity`

#### Declared In

`CCPhysicsNode.h`

### iterations

The number of solver iterations the underlying physics engine should run. This allows you to tune the performance and quality of the physics. Low numbers will improve performance, but make the physics spongy or rubbery. High numbers will use more CPU time, but make the physics look more solid. The default value is 10.

`@property (nonatomic, assign) int iterations`

#### Declared In

`CCPhysicsNode.h`

### sleepTimeThreshold

Physics bodies fall asleep when a group of them move slowly for longer than the threshold. Sleeping bodies use minimal CPU resources and wake automatically when a collision happens. Defaults to 0.5 seconds.

`@property (nonatomic, assign) CCTime sleepTimeThreshold`

#### Declared In

`CCPhysicsNode.h`

## Instance Methods

### pointQueryAt:within:block:

Find all CCPhysicsShapes within a certain distance of a point. The block is called once for each shape found.

`- (void)pointQueryAt:(CGPoint)point within:(CGFloat)radius block:(void ( ^ ) ( CCPhysicsShape *shape , CGPoint nearest , CGFloat distance ))block`

#### Parameters

point

  Center point of query.

radius

  Radius to sweep.

block

  Block to execute per result.

#### Declared In

`CCPhysicsNode.h`

### rayQueryFirstFrom:to:block:

Shoot a ray from ‘start’ to ‘end’ and find all of the CCPhysicsShapes that it would hit. The block is called once for each shape found.

`- (void)rayQueryFirstFrom:(CGPoint)start to:(CGPoint)end block:(void ( ^ ) ( CCPhysicsShape *shape , CGPoint point , CGPoint normal , CGFloat distance ))block`

#### Parameters

start

  Start point.

end

  End point.

block

  Block to execute per result.

#### Declared In

`CCPhysicsNode.h`

### rectQuery:block:

Find all CCPhysicsShapes whose bounding boxes overlap the given CGRect. The block is called once for each shape found.

`- (void)rectQuery:(CGRect)rect block:(void ( ^ ) ( CCPhysicsShape *shape ))block`

#### Parameters

rect

  Rectangle area to check.

block

  The block is called once for each shape found.

#### Declared In

`CCPhysicsNode.h`