Using Chipmunk Physics to create a iOS Game - Scott Lembcke

13
Chipmunk Physics and Cocos2D Scott Lembcke, Howling Moon Software 1 Saturday, March 23, 13

description

Scott's 3/21 presentation at Mobile March 2013

Transcript of Using Chipmunk Physics to create a iOS Game - Scott Lembcke

Page 1: Using Chipmunk Physics to create a iOS Game - Scott Lembcke

Chipmunk Physicsand Cocos2D

Scott Lembcke, Howling Moon Software

1

Saturday, March 23, 13

Page 2: Using Chipmunk Physics to create a iOS Game - Scott Lembcke

What is Chipmunk?

2

Saturday, March 23, 13

Page 3: Using Chipmunk Physics to create a iOS Game - Scott Lembcke

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

Page 4: Using Chipmunk Physics to create a iOS Game - Scott Lembcke

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

Page 5: Using Chipmunk Physics to create a iOS Game - Scott Lembcke

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

Page 6: Using Chipmunk Physics to create a iOS Game - Scott Lembcke

Space

Shapes

BodyJoint

6

Body

Saturday, March 23, 13

Page 7: Using Chipmunk Physics to create a iOS Game - Scott Lembcke

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

Page 8: Using Chipmunk Physics to create a iOS Game - Scott Lembcke

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

Page 9: Using Chipmunk Physics to create a iOS Game - Scott Lembcke

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

Page 10: Using Chipmunk Physics to create a iOS Game - Scott Lembcke

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

Page 11: Using Chipmunk Physics to create a iOS Game - Scott Lembcke

Code Time!

11

Saturday, March 23, 13

Page 12: Using Chipmunk Physics to create a iOS Game - Scott Lembcke

Fixed Time Steps

12

• Not required, but a really good idea

• “Fix your timestep” - gafferongames.com

Saturday, March 23, 13

Page 13: Using Chipmunk Physics to create a iOS Game - Scott Lembcke

Get the Source Codegithub.com/slembcke/ChipmunkColorMatch

13

Saturday, March 23, 13