Thursday, July 23, 2009

Generic Body

AddSpringBox(12,8,2,.1,-.45)

////////////////////////
public function AddSpringBox(_x:Number,_y:Number,_halfwidth:Number,_halfheight:Number,ang:Number):void {
var bodyDef:b2BodyDef = new b2BodyDef();
bodyDef.position.Set(_x,_y);
var boxDef:b2PolygonDef = new b2PolygonDef();
boxDef.SetAsBox(_halfwidth,_halfheight);
bodyDef.angle=ang
boxDef.density = 0.0;
boxDef.restitution=1
var body:b2Body = m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();





red=new Red;
red.x=body.GetPosition().x* 30;
red.y=body.GetPosition().y* 30;
red.scaleX=_halfwidth;
red.scaleY=_halfheight*2
red.rotation = body.GetAngle() * (180/Math.PI);

m_dbgSprite.addChild(red);
body.m_userData = red;
}

No comments:

FEEDJIT Live