Hi everyones!
First off, i'm a real noob using box2d! I wanted to know in the BoxMAn exemple the camera follow the player (Boxman). I've been using the BoxMan.as to use as my main class for my hero. All others things have been setup by using flash IDE. But that is i did not was able to find were is the code in all the Demo class to be able to make the camera also follow my player.
Also i've modified the structure of BoxMan to use my own MC'S with animation in it. Here no problems everything works fine. But here it is I would like to be able to replace the b2body.ApplyImpulse(new V2(-0.12, 0), b2body.GetWorldCenter()); to //b2body.SetLinearVelocity(new V2(-2, 0)); but the problem is when my player jump and i hit the left he fly straigth to the left with is walking animation-like hes walking in the air!!!!!! I don't really know to do that! So here my code rigth now :
Code:
public class BoxMan extends Box {
public var contacts:ContactList;
public override function create():void {
reportBeginContact = true;
reportEndContact = true;
fixedRotation = true;
super.create();
listenWhileVisible(world, StepEvent.STEP, parseInput, false, 10);
listenWhileVisible(this, ContactEvent.BEGIN_CONTACT, handleContact);
contacts = new ContactList();
contacts.listenTo(this);
}
public function handleContact(e:ContactEvent):void {
}
public function parseInput(e:Event):void {
var manifold:b2WorldManifold = null;
var dot:Number = -1;
if(!contacts.isEmpty()) {
contacts.forEach(function(keys:Array, c:ContactEvent) {
var wm:b2WorldManifold = c.getWorldManifold();
if(wm.normal) {
var d:Number = wm.normal.dot(gravity);
if(!manifold || d > dot) {
manifold = wm;
dot = d;
}
}
});
contacts.clean();
}
var left:Boolean = Input.kd('A', 'LEFT');
var right:Boolean = Input.kd('D', 'RIGHT');
var jump:Boolean = Input.kp(' ', 'UP');
var v:V2;
if(jump && manifold) {
v = manifold.normal.clone().multiplyN(-3);
b2body.ApplyImpulse(v, b2body.GetWorldCenter());
this.gotoAndStop("jump");
}
else if(left) {
//b2body.ApplyImpulse(new V2(-0.12, 0), b2body.GetWorldCenter());
b2body.SetLinearVelocity(new V2(-2, 0)); //I've just applied it to the left rigth now!
this.gotoAndStop("run");
this.scaleX=1;
}
else if(right) {
b2body.ApplyImpulse(new V2(0.12, 0), b2body.GetWorldCenter());
this.gotoAndStop("run");
this.scaleX=-1;
}
else {
this.gotoAndStop("idle");
}
}
}
}
Don't worry everything is include!!! Thanks all in advance!!!!