class CP::CollisionHandler

Overview

Defines callbacks to configure custom collision handling.

Collision handlers have a pair of types; when a collision occurs between two shapes that have these types, the collision handler functions are triggered.

Shapes tagged as sensors (Shape#sensor? == true) never generate collisions that get processed, so collisions between sensors shapes and other shapes will never call the #post_solve callback. They still generate #begin, and #separate callbacks, and the #pre_solve callback is also called every frame even though there is no collision response.

#pre_solve callbacks are called before the sleeping algorithm runs. If an object falls asleep, its #post_solve callback won't be called until it's reawoken.

Defined in:

chipmunk/collision.cr

Instance Method Summary

Instance Method Detail

def begin(arbiter : Arbiter, space : Space) : Bool #

This function is called when two shapes with types that match this collision handler begin colliding.

Returning false from a begin callback causes the collision to be ignored until the the separate callback is called when the objects stop colliding.


[View source]
def post_solve(arbiter : Arbiter, space : Space) #

This function is called each step when two shapes with types that match this collision handler are colliding.

It's called after the collision solver runs, so you can retrieve the collision impulse or kinetic energy if you want to use it to calculate sound volumes or damage amounts.


[View source]
def pre_solve(arbiter : Arbiter, space : Space) : Bool #

This function is called each step when two shapes with types that match this collision handler are colliding.

It's called before the collision solver runs so that you can affect a collision's outcome (by editing Arbiter#friction, Arbiter#restitution, Arbiter#surface_velocity).

Returning false from a pre-step callback causes the collision to be ignored until the next step.


[View source]
def separate(arbiter : Arbiter, space : Space) #

This function is called when two shapes with types that match this collision handler stop colliding.

To ensure that #begin/#separate are always called in balanced pairs, it will also be called when removing a shape while it's in contact with something or when deallocating the space.


[View source]
def type_a : UInt64 #

Collision type identifier of the first shape that this handler recognizes.

In the collision handler callback, the shape with this type will be the first argument.


[View source]
def type_b : UInt64 #

Collision type identifier of the second shape that this handler recognizes.

In the collision handler callback, the shape with this type will be the second argument.


[View source]