Things used for handling physics simulation. More...
Classes | |
class | CpArbiter |
arbitrates collisions between sprites using Chipmunk Physics (Chipmunk Physics Only) More... | |
class | CpConstraint |
describes how two sprites are connected to one another (Chipmunk Physics Only) More... | |
class | CpSpace |
container for simulating objects (Chipmunk Physics Only) More... | |
class | ISpriteCollideHelper |
helper for deciding whether 2 sprites should collide or not More... | |
struct | SpriteBreakEvent |
a Sprite joint is breaking because it was overstressed (Chipmunk Physics Only) More... | |
struct | SpriteCollideEvent |
a Sprite collided with something (Optional) More... | |
Variables | |
const | action_CollideSprite = 0 |
const | action_CollideWall = 1 |
eventType_SpriteAnimate action: a sprite has hit the edge of the sprite layer More... | |
const | action_JointBreak = 13 |
Things used for handling physics simulation.
class pdg::ISpriteCollideHelper |
helper for deciding whether 2 sprites should collide or not
Implement this interface to do handle special case collision logic between two sprites. For example, you might want bullet sprites to collide with enemy sprites but not with one another. If a collide helper is installed, then on initial contact between two sprites the collide helper for the moving sprite will be called, and you the helper can decide if the collision should happen or not.
For those coding in Javascript, there is an implementation of ISpriteCollideHelper that maps a function definition to the draw call. So to create a helper:
If you need something more complex, you can also use classify to create a new Javascript class that derives from pdg.ISpriteCollideHelper, and it will call the allowCollision() method of your class. For example:
As you can see from the examples above, your Sprite Collide Helper function (or allowCollision() method) will be called with two parameters, and return a boolean:
struct pdg::SpriteBreakEvent |
a Sprite joint is breaking because it was overstressed (Chipmunk Physics Only)
This event is generated by a Sprite whenever the forces acting on a joint with another Sprite are greater then the breaking force of the joint. To prevent the break from happening, return true from the handler that gets this event. If you return false then the joint will go ahead and break.
{ emitter: {}, // the emitter that generated this event eventType: 21, // the event type (eventType_SpriteBreak) action: 13, // what happened (action_JointBreak) actingSprite: {}, // the Sprite to which the forces were applied inLayer: {}, // the SpriteLayer that contains the Sprite targetSprite: {}, // the Sprite that was previously joined impulse: { // the impulse applied x: 29.35, y: 0.883 }, force: 384.0, // the force of the collision breakForce: 100.0, // the maximum force the joint could stand before breaking joint: {} // the CpConstraint that defines the joint }
struct pdg::SpriteCollideEvent |
a Sprite collided with something (Optional)
This event is generated by a Sprite whenever it hits something. If it hits another Sprite action will be action_CollideSprite, if it hits a wall it will be action_CollideWall.
{ emitter: {}, // the emitter that generated this event eventType: 20, // the event type (eventType_SpriteCollide) action: 0, // what happened (action_CollideSprite or action_CollideWall) actingSprite: {}, // the moving Sprite inLayer: {}, // the SpriteLayer that contains the Sprite targetSprite: {}, // the Sprite that was collided with (if action was action_CollideSprite) normal: { // the normal vector for the collision x: 1.0, y: 0.0 }, impulse: { // the impulse imparted by the collision x: 29.35, y: 0.883 }, force: 384.0, // the force of the collision kineticEnergy:883 // the total kinetic energy of the collision }
Need a lot more documentation on Collisions
Calculate kinetic energy of collision for Sprites not using Chipmunk Physics
action_CollideSprite = 0 |
action_CollideWall = 1 |
eventType_SpriteAnimate action: a sprite has hit the edge of the sprite layer
These events are only sent for sprites that have setWantsCollideWallEvents(true) and where the SpriteLayer has a size explicitly set.
action_JointBreak = 13 |