Hey guys, I'm placing my bets on Box2DAS3 for my physics after trying out a few engines. It seems like its a little more work - but worth it. Of course, I'd rather it be more like the whole DisplayObject hierarchy, so I'm trying to make an object that extends the b2Body and just have to pass a few params when calling new to create both a body, shape, and its sprite representation all in the same object. I'm having trouble actually creating the body. My positional settings are a bit off compared to debug output, but I'll get to that later. Basically - I'm assuming that world.CreateBody would do the same thing as super( bodydef, world) - but my shapes don't actually move. I can only get gravitational movement when I create a body from a shape outside of this class and run CreateBody there.

Also, as you can see I was trying out something else where I wanted to set the super class to the created body, but that doesn't fly when compiling. Anybody have any hints how I can make this work? I'm close - I had it working as Block extends b2BodyDef before - but if I'm going to access my update handler from my m_bodylist array, I need this class to be a b2Body.

Thanks!
ben

var b:Block = new Block( world, 10, 10 );
     b.x = c*5;
     b.y = c*15;

   public class Block extends b2Body implements IObject
{ public function Block( world:b2World, w:Number, h:Number, density:Number = 1.0, friction:Number = .5, restitution:Number = 0.2 ) { _bodydef = new b2BodyDef();
           _bodydef.userData = new Sprite();
           _bodydef.userData.graphics.lineStyle(.5,0x000000);
           _bodydef.userData.graphics.beginFill(0xFFFF00);
           _bodydef.userData.graphics.drawRect(0,0,w,h);
           _bodydef.userData.graphics.endFill();
_poly.SetAsBox(w/60, h/60);
           _poly.density = density;
           _poly.friction = friction;
           _poly.restitution = restitution;
super( _bodydef, world );
           //super = world.CreateBody(_bodydef as b2BodyDef);
           super.CreateShape(this.shape);
           super.SetMassFromShapes();
       }
public function update():void {} // empty, but I'm accessing b2Body properties outside of this class for now

       public function get display():Sprite { return _bodydef.userData; }
       public function get shape():b2ShapeDef { return _poly; }
       public function get bodydef():b2BodyDef { return _bodydef; }
public function set x( val:int ):void { _bodydef.position.x = val/60; display.x = val; } public function set y( val:int ):void { _bodydef.position.y = val/30; display.y = val; } public function get x():int { return _bodydef.position.x*60; }
       public function get y():int { return _bodydef.position.y*60; }
private var _poly:b2PolygonDef = new b2PolygonDef();
       private var _bodydef:b2BodyDef;
}
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to