Hi I am using box2d and I have a circle shape, I am trying to get a sprite to act as a costume to mask the body, but the sprite doesent move, only inserted in the world. I have an actor class and a ballActor that extends actor.
Actor:
...
ballActor:
the problem that happens is when I add it to main class and add it to an array so I can call updateLook() in the new frameevent listenr:
the sprite and body are only added at the top left corner, not the point i ask it and more importantly **the sprite doesent move**, what am I doing wrong? Is there a more proper way to update the sprite location?
Actor:
Code: Select all
public function Actor(myBody:b2Body, myCostume:DisplayObject)
{
_body = myBody;
_body.SetUserData(this);
_costume = myCostume;
updateMyLook();
}
...
Code: Select all
private function updateMyLook():void
{
_costume.x = _body.GetPosition().x * PhysiVals.RATIO;
_costume.y = _body.GetPosition().y * PhysiVals.RATIO;
_costume.rotation = _body.GetAngle() * (180 / Math.PI);
}
ballActor:
Code: Select all
public var fixtureDef:b2FixtureDef = new b2FixtureDef();
public function ballActor(parent:DisplayObjectContainer ,location:Point)
{
var fred:Sprite = new Fred();
fred.scaleX = BALL_SIZE / fred.width;
fred.scaleY = BALL_SIZE / fred.height;
parent.addChild(fred);
var wheelShape:b2CircleShape = new b2CircleShape(BALL_SIZE / PhysiVals.RATIO);
fixtureDef.shape = wheelShape;
fixtureDef.density=1;
fixtureDef.friction=5;
fixtureDef.density = 0.1;
var wheel:b2Body;
var BodyDef:b2BodyDef = new b2BodyDef();
BodyDef.type=b2Body.b2_dynamicBody;
BodyDef.allowSleep = false;
BodyDef.position.Set(location.x / PhysiVals.RATIO, location.y / PhysiVals.RATIO);
wheel = PhysiVals.world.CreateBody(BodyDef);
wheel.CreateFixture(fixtureDef);
super(wheel, fred);
}the problem that happens is when I add it to main class and add it to an array so I can call updateLook() in the new frameevent listenr:
Code: Select all
var ball:ballActor = new ballActor(_camera, new Point(240 / PhysiVals.RATIO, 20 / PhysiVals.RATIO));
_allActors.push(ball);
the sprite and body are only added at the top left corner, not the point i ask it and more importantly **the sprite doesent move**, what am I doing wrong? Is there a more proper way to update the sprite location?