Transcript
Page 1: ActionScript Box2D Quick Start

Box2D AS3 Quick Start

Chris Black

Page 2: ActionScript Box2D Quick Start

What is Box2D for Flash?

• “Box2DFlashAS3 is an open source port of Erin Catto's powerful c++ physics library Box2D.”

–Box2DFlash

• Current version 2.0.1 Flash and 1.4.3.1 for JavaScript.

• Box2D can be used to quickly add ‘real life’ physics to your Flash / Flex projects.

Page 3: ActionScript Box2D Quick Start

Uses of Box2D

• Games, physics demos and… games.• Very little practical application outside of

games.• Clients looking for animation often feel Box2D

looks too ‘real.’

Page 4: ActionScript Box2D Quick Start

AS3 Physics Comparison

• For a great comparison on physics engines available for Flash check out this post:

• http://www.emanueleferonato.com/2008/04/24/flash-physics-engines-galore/

Page 5: ActionScript Box2D Quick Start

Box2D vs Flash CS5

• Flash CS5 has a built in engine for creating STATIC demos.

• Box2D should be used when user interaction is required for DYNAMIC apps.

• If your animation changes based on user interaction, use Box2D.

Page 6: ActionScript Box2D Quick Start

Getting Started

• Grab the quick start demo from Google Code

Starting from scratch:• Add the SWC or download Box2D source• Set up your constants• Create a world with boundries• Add objects to the world

Page 7: ActionScript Box2D Quick Start

Constants

public static const PHYS_SCALE:Number = 10;// Number of pixels in a Meter.

public static const TIMESTEP:Number = 1.0 / 15.0;// How many physical calculations per timestep.

Usually 1 / 15 or 1 / 60.

public static const ITERATIONS:Number = 10.0;// The suggested iteration count is 10.

Page 8: ActionScript Box2D Quick Start

Create a World

Page 9: ActionScript Box2D Quick Start

2D Object VO

Page 10: ActionScript Box2D Quick Start

Create an Object

Page 11: ActionScript Box2D Quick Start

Add Object to the World

Page 13: ActionScript Box2D Quick Start

Box2D for Android

• GPU Acceleration• CacheAsBitmapMatrix• 30 fps on the Nexus One• Video demo on Nexus One

Page 14: ActionScript Box2D Quick Start

Box2D for iOS

• Box2D doesn’t perform well using the iOS exporter within Flash CS5.

• This might improve with future iterations but for now use native Objective-C for iOS apps that require physics.

Page 15: ActionScript Box2D Quick Start

Box2D for JavaScript

• Older version compared to Flash• Doesn’t perform as well on a PC• Takes longer to code• Worth trying out but needs some major

updates before it will compare to Flash.

Page 16: ActionScript Box2D Quick Start

Now what?

• Downloadhttp://box2dflash.sourceforge.net/http://box2d-js.sourceforge.net/

• Learnhttp://www.emanueleferonato.com/category/box2d/http://www.blackcj.com/blog/tag/box2d/


Top Related