actionscript box2d quick start
DESCRIPTION
Box2D is the most powerful and widely used physics engine for Flash. It allows developers to quickly create dynamic, life like, environments for games and applications. In this session we'll cover everything you need to get started with the latest version of Box2D. Learn how to create a 2D world, add objects and apply forces. All source code for the demo will be provided and we'll finish with an example of Box2D running on the Nexus One with Adobe AIR!TRANSCRIPT
Box2D AS3 Quick Start
Chris Black
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.
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.’
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/
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.
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
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.
Create a World
2D Object VO
Create an Object
Add Object to the World
Demo
Basketball Demo
Car Demo
Box2D for Android
• GPU Acceleration• CacheAsBitmapMatrix• 30 fps on the Nexus One• Video demo on Nexus One
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.
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.
Now what?
• Downloadhttp://box2dflash.sourceforge.net/http://box2d-js.sourceforge.net/
• Learnhttp://www.emanueleferonato.com/category/box2d/http://www.blackcj.com/blog/tag/box2d/