Chipmunk Physicsand Cocos2D
Scott Lembcke, Howling Moon Software
1
Saturday, March 23, 13
What is Chipmunk?
2
Saturday, March 23, 13
What is Chipmunk?
• Open source 2D rigid body physics engine
• Rigid body == non-deformable shapes
• Collision detection
• Joints (and other constraints)
• Queries (point, raycast, etc)
3
Saturday, March 23, 13
Fancy Features
• Collision: spatial indexing, filtering, event callbacks, collision forces
• Object sleeping
• Contact graph
• Joint callbacks
• Pro features: NEON / multicore, autogeometry, Obj-C binding.
4
Saturday, March 23, 13
What is Cocos2D
• Open source 2D game framework
• Scene graphs (sprites, particles, shaders, ...)
• Game states
• Transitions, input, timers, menus
• Asset management (sounds, textures, ...)
• Popularity: tool support, cross-platform
5
Saturday, March 23, 13
Space
Shapes
BodyJoint
6
Body
Saturday, March 23, 13
Chipmunk Spaces
• Global values (gravity, damping, quality, etc)
• Has lists of bodies, shapes and constraints
• cpSpaceStep() - updates time
• Tracks collision callbacks
• Queries (point, raycast, shape, bounds)
7
Saturday, March 23, 13
Chipmunk Bodies
• Physical properties (mass, moment)
• Location/movement
• Position, velocity, force
• Angle, angular velocity, torque
• Has no shape or size on its own
• Can be static, dynamic or rogue
8
Saturday, March 23, 13
Chipmunk Shapes
• Gives shape to rigid bodies
• Allows them to collide
• Material properties (friction, bounciness)
• Circles, line segments, convex polygons
• Multiple shapes per body allowed
• Always filled (no hollow shapes)
9
Saturday, March 23, 13
Simple Matching Game
• Ignore scoring logic
• Basic mechanics:
• Match groups of 4 - collision callbacks
• Tap a ball to remove it - queries
• Horses!
10
Saturday, March 23, 13
Code Time!
11
Saturday, March 23, 13
Fixed Time Steps
12
• Not required, but a really good idea
• “Fix your timestep” - gafferongames.com
Saturday, March 23, 13
Get the Source Codegithub.com/slembcke/ChipmunkColorMatch
13
Saturday, March 23, 13
Top Related