📎 Webclip
Physics with Box2D - Impact
The page introduces Box2D as a way to get more accurate physics in Impact, beyond its basic collision detection and response. It notes the JavaScript port, the namespace changes, and the module wrapper used so Box2D can load in Impact, then points to the Box2D 2.0.2 manual and a demo.
Reading notes#
- Box2D is presented as a physics engine for cases where Impact’s built-in collision handling is not enough.
- The JavaScript version used here comes from Jonas Wagner’s port, with Box2D classes placed under the
b2.namespace. - The page links to the Box2D 2.0.2 manual.
- A Box2D world is created with a bounding box, gravity vector, and
b2.Worldinstance. - A body is added by defining a
b2.BodyDef, creating the body in the world, and attaching ab2.PolygonDefshape. - Box2D body positions use the object’s center, unlike Impact entities, which use the upper-left corner.
SetAsBoxtakes half-width and half-height values, so the example box becomes 10 by 10 units.- The physics simulation advances in the game update method with
b2.World.Step, usingig.system.tickas the timestep. - Box2D units are tuned for meters, so the page uses
b2.SCALEto convert from pixels to meters. ig.Box2DGameandig.Box2DEntityare described as helper classes that handle the integration work.ig.Box2DGame.loadLevel()builds physics objects from a collision map and combines adjacent tile regions into larger rectangles.- The page says Box2D performance seems more tied to the number of collisions than the number of objects.
debugCollisionRectscan draw collision boxes as green outlines.ig.Box2DEntitycreates a physics body sized like the entity and updates the entity position from the physics simulation.- A crate entity can subclass
ig.Box2DEntity, disable normal Impact collision handling, and use an animation sheet. - Movement should use Box2D forces and impulses, with the example showing
ApplyForcefor a jetpack jump input.
