Can you get the objects to float in space using your mouse? This is the conclusion to the three part series on using the Box2D Physics engine with ActionScript.
Box2D Anti-Gravity Example:
(click and hold the mouse down for anti-gravity)
Now that we have a Box2D environment set up and lots of polygons in it, let’s make it cool.
Anti-gravity boolean.
Add this boolean and if statement into your shape environment class.
public var counterGravity:Boolean = false; override protected function update(e:Event):void { // ...(from part 2)... // if (bb.m_userData is Sprite) { if(counterGravity){ world.SetGravity(new b2Vec2(0,-9.8)); bb.WakeUp(); }else{ world.SetGravity(new b2Vec2(0,9.8)); } // ...(from part 2)... // }
Now add a mouse event handler and the following functions into your main class.
private function addCounterGravity(event:MouseEvent):void { _shape2d.counterGravity = true; } private function removeCounterGravity(event:MouseEvent):void { _shape2d.counterGravity = false; }
Now you have anti-gravity!
Miss out on the basics? Check out part 1 and part 2 of this series.
Full source code here.