Chipmunk2D Pro API Reference  6.1.5
 All Classes Functions Variables Typedefs Properties Groups Pages
Public Types | Instance Methods | Class Methods | Properties | List of all members
ChipmunkSpace Class Reference

Inherits NSObject.

Inherited by ChipmunkHastySpace.

Public Types

typedef void(^ ChipmunkPostStepBlock )(void)
 Block type used with [ChipmunkSpace addPostStepBlock:].
 

Instance Methods

(bool enableContactGraph) - __attribute__
 
(void) - setDefaultCollisionHandler:begin:preSolve:postSolve:separate:
 Set the default collision handler. More...
 
(void) - addCollisionHandler:typeA:typeB:begin:preSolve:postSolve:separate:
 Set a collision handler to handle specific collision types. More...
 
(void) - removeCollisionHandlerForTypeA:andB:
 Remove a collision handler.
 
(id) - add:
 Add an object to the space. More...
 
(id) - remove:
 Remove an object from the space. More...
 
(BOOL) - contains:
 Check if a space already contains a particular object:
 
(id) - smartAdd:
 If the space is locked and it's unsafe to call add: it will call addPostStepAddition: instead.
 
(id) - smartRemove:
 If the space is locked and it's unsafe to call remove: it will call addPostStepRemoval: instead.
 
(NSArray *) - addBounds:thickness:elasticity:friction:layers:group:collisionType:
 Handy utility method to add a border of collision segments around a box. More...
 
(BOOL) - addPostStepCallback:selector:key:
 Define a callback to be run just before [ChipmunkSpace step:] finishes. More...
 
(BOOL) - addPostStepBlock:key:
 Same as [ChipmunkSpace addPostStepCallback:] but with a block. The block is copied.
 
(void) - addPostStepAddition:
 Add the Chipmunk Object to the space at the end of the step.
 
(void) - addPostStepRemoval:
 Remove the Chipmunk Object from the space at the end of the step.
 
(NSArray *) - nearestPointQueryAll:maxDistance:layers:group:
 Return an array of ChipmunkNearestPointQueryInfo objects for shapes within maxDistance of point. More...
 
(ChipmunkNearestPointQueryInfo *) - nearestPointQueryNearest:maxDistance:layers:group:
 Find the closest shape to a point that is within maxDistance of point. More...
 
(NSArray *) - pointQueryAll:layers:group:
 Returns a NSArray of all shapes that overlap the given point. More...
 
(ChipmunkShape *) - pointQueryFirst:layers:group:
 Returns the first shape that overlaps the given point. More...
 
(NSArray *) - segmentQueryAllFrom:to:layers:group:
 Return a NSArray of ChipmunkSegmentQueryInfo objects for all the shapes that overlap the segment. The objects are unsorted.
 
(ChipmunkSegmentQueryInfo *) - segmentQueryFirstFrom:to:layers:group:
 Returns the first shape that overlaps the given segment. The segment is treated as having the given group and layers.
 
(NSArray *) - bbQueryAll:layers:group:
 Returns a NSArray of all shapes whose bounding boxes overlap the given bounding box. The box is treated as having the given group and layers.
 
(NSArray *) - shapeQueryAll:
 Returns a NSArray of ChipmunkShapeQueryInfo objects for all the shapes that overlap shape.
 
(BOOL) - shapeTest:
 Returns true if the shape overlaps anything in the space.
 
(void) - activateShapesTouchingShape:
 Perform a shape query for shape and call cpBodyActivate() for everythnig it touches.
 
(NSArray *) - bodies
 Get a copy of the list of all the bodies in the space.
 
(NSArray *) - shapes
 Get a copy of the list of all the shapes in the space.
 
(NSArray *) - constraints
 Get a copy of the list of all the constraints in the space.
 
(void) - reindexStatic
 Update all the static shapes.
 
(void) - reindexShape:
 Update the collision info for a single shape. More...
 
(void) - reindexShapesForBody:
 Update the collision info for all shapes attached to a body.
 
(void) - step:
 Step time forward. While variable timesteps may be used, a constant timestep will allow you to reduce CPU usage by using fewer iterations.
 
(ChipmunkBody *) - addBody:
 Add a body to the space. Normally you would simply use add:.
 
(ChipmunkBody *) - removeBody:
 Remove a body to the space. Normally you would simply use remove:.
 
(ChipmunkShape *) - addShape:
 Add a shape to the space. Normally you would simply use add:.
 
(ChipmunkShape *) - removeShape:
 Remove a shape to the space. Normally you would simply use remove:.
 
(ChipmunkShape *) - addStaticShape:
 Add a static shape to the space. Normally you would simply create a static shape use add:.
 
(ChipmunkShape *) - removeStaticShape:
 Remove a static shape to the space. Normally you would simply create a static shape use remove:.
 
(ChipmunkConstraint *) - addConstraint:
 Add a constraint to the space. Normally you would simply use add:.
 
(ChipmunkConstraint *) - removeConstraint:
 Remove a constraint to the space. Normally you would simply use remove:.
 

Class Methods

(ChipmunkSpace *) + spaceFromCPSpace:
 Get the ChipmunkSpace object associciated with a cpSpace pointer. More...
 

Properties

int iterations
 The iteration count is how many solver passes the space should use when solving collisions and joints (default is 10). More...
 
cpVect gravity
 Global gravity value to use for all rigid bodies in this space (default value is cpvzero).
 
cpFloat damping
 Global viscous damping value to use for all rigid bodies in this space (default value is 1.0 which disables damping). More...
 
cpFloat idleSpeedThreshold
 If a body is moving slower than this speed, it is considered idle. The default value is 0, which signals that the space should guess a good value based on the current gravity.
 
cpFloat sleepTimeThreshold
 Elapsed time before a group of idle bodies is put to sleep (defaults to infinity which disables sleeping). More...
 
cpFloat collisionSlop
 Amount of encouraged penetration between colliding shapes. More...
 
cpFloat collisionBias
 Determines how fast overlapping shapes are pushed apart. More...
 
cpTimestamp collisionPersistence
 Number of frames that contact information should persist. More...
 
cpSpacespace
 Returns a pointer to the underlying cpSpace C struct.
 
ChipmunkBodystaticBody
 The space's designated static body. More...
 
cpFloat currentTimeStep
 Retrieves the current (if you are in a callback from [ChipmunkSpace step:]) or most recent (outside of a [ChipmunkSpace step:] call) timestep.
 
id data
 An object that this space is associated with. More...
 

Method Documentation

- (bool enableContactGraph) __attribute__ ((__deprecated__)) 
Deprecated:
6.0.4 Does nothing, and is a no-op. The contact graph is always enabled now.
- (id) add: (NSObject< ChipmunkObject > *)  obj

Add an object to the space.

This can be any object that implements the ChipmunkObject protocol. This includes all the basic types such as ChipmunkBody, ChipmunkShape and ChipmunkConstraint as well as any composite game objects you may define that implement the protocol.

Warning
This method may not be called from a collision handler callback. See smartAdd: or ChipmunkSpace.addPostStepCallback:selector:context: for information on how to do that.
- (NSArray *) addBounds: (CGRect)  bounds
thickness: (cpFloat radius
elasticity: (cpFloat elasticity
friction: (cpFloat friction
layers: (cpLayers layers
group: (id)  group
collisionType: (id)  collisionType 

Handy utility method to add a border of collision segments around a box.

See ChipmunkShape for more information on the other parameters. Returns an NSArray of the shapes. Since NSArray implements the ChipmunkObject protocol, you can use the [ChipmunkSpace remove:] method to remove the bounds.

- (void) addCollisionHandler: (id)  delegate
typeA: (cpCollisionType a
typeB: (cpCollisionType b
begin: (SEL)  begin
preSolve: (SEL)  preSolve
postSolve: (SEL)  postSolve
separate: (SEL)  separate 

Set a collision handler to handle specific collision types.

The methods are called only when shapes with the specified collisionTypes collide.

typeA and typeB should be the same object references set to ChipmunkShape.collisionType. They can be any uniquely identifying object. Class and global NSString objects work well as collision types as they are easy to get a reference to and do not require you to allocate any objects.

The expected method selectors are as follows:

- (bool)begin:(cpArbiter *)arbiter space:(ChipmunkSpace*)space
- (bool)preSolve:(cpArbiter *)arbiter space:(ChipmunkSpace*)space
- (void)postSolve:(cpArbiter *)arbiter space:(ChipmunkSpace*)space
- (void)separate:(cpArbiter *)arbiter space:(ChipmunkSpace*)space
- (BOOL) addPostStepCallback: (id)  target
selector: (SEL)  selector
key: (id)  key 

Define a callback to be run just before [ChipmunkSpace step:] finishes.

The main reason you want to define post-step callbacks is to get around the restriction that you cannot call the add/remove methods from a collision handler callback. Post-step callbacks run right before the next (or current) call to step: returns when it is safe to add and remove objects. You can only schedule one post-step callback per key value, this prevents you from accidentally removing an object twice. Registering a second callback for the same key is a no-op.

The method signature of the method should be:

- (void)postStepCallback:(id)key</code></pre>

This makes it easy to call a removal method on your game controller to remove a game object that died or was destroyed as the result of a collision:

[space addPostStepCallback:gameController selector:@selector(remove:) key:gameObject];
Attention
Not to be confused with post-solve collision handler callbacks.
Warning
target and object cannot be retained by the ChipmunkSpace. If you need to release either after registering the callback, use autorelease to ensure that they won't be deallocated until after [ChipmunkSpace step:] returns.
See Also
- addPostStepRemoval:
- (NSArray *) nearestPointQueryAll: (cpVect point
maxDistance: (cpFloat maxDistance
layers: (cpLayers layers
group: (cpGroup group 

Return an array of ChipmunkNearestPointQueryInfo objects for shapes within maxDistance of point.

The point is treated as having the given group and layers.

- (ChipmunkNearestPointQueryInfo *) nearestPointQueryNearest: (cpVect point
maxDistance: (cpFloat maxDistance
layers: (cpLayers layers
group: (cpGroup group 

Find the closest shape to a point that is within maxDistance of point.

The point is treated as having the given layers and group.

- (NSArray *) pointQueryAll: (cpVect point
layers: (cpLayers layers 

Returns a NSArray of all shapes that overlap the given point.

The point is treated as having the given group and layers.

Deprecated:
- (ChipmunkShape *) pointQueryFirst: (cpVect point
layers: (cpLayers layers 

Returns the first shape that overlaps the given point.

The point is treated as having the given group and layers.

Deprecated:
- (void) reindexShape: (ChipmunkShape *)  shape

Update the collision info for a single shape.

Can be used to update individual static shapes that were moved or active shapes that were moved that you want to query against.

- (id) remove: (NSObject< ChipmunkObject > *)  obj

Remove an object from the space.

This can be any object that implements the ChipmunkObject protocol. This includes all the basic types such as ChipmunkBody, ChipmunkShape and ChipmunkConstraint as well as any composite game objects you may define that implement the protocol.

Warning
This method may not be called from a collision handler callback. See smartRemove: or ChipmunkSpace.addPostStepCallback:selector:context: for information on how to do that.
- (void) setDefaultCollisionHandler: (id)  delegate
begin: (SEL)  begin
preSolve: (SEL)  preSolve
postSolve: (SEL)  postSolve
separate: (SEL)  separate 

Set the default collision handler.

The default handler is used for all collisions when a specific collision handler cannot be found.

The expected method selectors are as follows:

- (bool)begin:(cpArbiter *)arbiter space:(ChipmunkSpace*)space
- (bool)preSolve:(cpArbiter *)arbiter space:(ChipmunkSpace*)space
- (void)postSolve:(cpArbiter *)arbiter space:(ChipmunkSpace*)space
- (void)separate:(cpArbiter *)arbiter space:(ChipmunkSpace*)space
+ (ChipmunkSpace *) spaceFromCPSpace: (cpSpace *)  space

Get the ChipmunkSpace object associciated with a cpSpace pointer.

Undefined if the cpSpace wasn't created using Objective-Chipmunk.

Property Documentation

- (cpFloat) collisionBias
readwritenonatomicassign

Determines how fast overlapping shapes are pushed apart.

Expressed as a fraction of the error remaining after each second. Defaults to pow(1.0 - 0.1, 60.0) meaning that Chipmunk fixes 10% of overlap each frame at 60Hz.

- (cpTimestamp) collisionPersistence
readwritenonatomicassign

Number of frames that contact information should persist.

Defaults to 3. There is probably never a reason to change this value.

- (cpFloat) collisionSlop
readwritenonatomicassign

Amount of encouraged penetration between colliding shapes.

Used to reduce oscillating contacts and keep the collision cache warm. Defaults to 0.1. If you have poor simulation quality, increase this number as much as possible without allowing visible amounts of overlap.

- (cpFloat) damping
readwritenonatomicassign

Global viscous damping value to use for all rigid bodies in this space (default value is 1.0 which disables damping).

This value is the fraction of velocity a body should have after 1 second. A value of 0.9 would mean that each second, a body would have 80% of the velocity it had the previous second.

- (id) data
readwritenonatomicassign

An object that this space is associated with.

You can use this get a reference to your game state or controller object from within callbacks.

Attention
Like most delegate properties this is a weak reference and does not call retain. This prevents reference cycles from occuring.
- (int) iterations
readwritenonatomicassign

The iteration count is how many solver passes the space should use when solving collisions and joints (default is 10).

Fewer iterations mean less CPU usage, but lower quality (mushy looking) physics.

- (cpFloat) sleepTimeThreshold
readwritenonatomicassign

Elapsed time before a group of idle bodies is put to sleep (defaults to infinity which disables sleeping).

If an entire group of touching or jointed bodies has been idle for at least this long, the space will put all of the bodies into a sleeping state where they consume very little CPU.

- (ChipmunkBody*) staticBody
readnonatomicassign

The space's designated static body.

Collision shapes added to the body will automatically be marked as static shapes, and rigid bodies that come to rest while touching or jointed to this body will fall asleep.


The documentation for this class was generated from the following file: