Haxe Physics Engine

Physaxe is a 2D Rigid Body Physics engine written in Haxe. It can be compiled on all platforms but has been optimized for Flash Player 9. See http://code.google.com/p/physaxe


haxelib install physaxe

Here's the demo, please use 1-9 keys to change the demo and click to fire a block and press space to vew the collisions :



class Test {

        static var world : phx.World;

        static function main() {
                // define the size of the world
                var size = new phx.col.AABB(-1000,-1000,1000,1000);
                // create the broadphase : this is the algorithm used to optimize collision detection
                var bf = new phx.col.SortedList();
                // initialize the world
                world = new phx.World(size,bf);
                // create one 50x50 box body at x=210,y=-50
                var b1 = new phx.Body(210,-50);
                b1.addShape( phx.Shape.makeBox(50,50) );
                // create one 30 radius circle at x=200,y=250
                var b2 = new phx.Body(200,250);
                b2.addShape( new phx.Circle(30,new phx.Vector(0,0)) );
                // create one 20x20 box body at x=100,y=270
                var b3 = new phx.Body(100,270);
                b3.addShape( phx.Shape.makeBox(20,20) );
                // add the created bodies to the world
                // creates a 270x50 box at x=0,y=280
                var floor = phx.Shape.makeBox(270,50,0,280);
                // the floor is static, it can't move
                // setup gravity
                world.gravity = new phx.Vector(0,0.9);

                // for every frame, call the loop method

        static function loop(_) {
                // update the world
                // clear the graphics
                var g = flash.Lib.current.graphics;
                // draw the world
                var fd = new phx.FlashDraw(g);
                fd.drawCircleRotation = true;



You can compile this code with the following test.hxml file :
-swf test.swf
-swf-version 9
-swf-header 400:300:30
-main Test
-lib physaxe
version #10599, modified 2011-06-05 15:26:03 by commanderz