How to Use .as Exported File from PhysicsEditor

208 Views Asked by At

The question was here for a long time with bounty and no satisfying solution for me. I erased the first post and am posting instead a question that can be answered quickly with a yes or no so I can proceed with my doings.

If you could answer it really fast before it's deleted by "not a good question". Is using a custom shape from PhysicsEditor to Nape the same as doing it with Box2D? (ofc changing syntax)

If you could then give a look in that link then say it's the same process in Nape that'll be enought thanks.

I ask this because I found the Box2D tutorial easier to follow so far.

public var floor:Body;

floor = new Body(BodyType.STATIC);
var floorShape:PhysicsData = new PhysicsData();
floor.shapes.add(floorShape); // Error: Implicit coercion of a value of type PhysicsData to an unrelated type nape.shape:Shape.
floor.space = space;
1

There are 1 best solutions below

6
On

Update:

According to a comment on this blog post, it sounds like recent versions of Nape have broken compatibility with the physics editor. Specifically, the graphic and graphicUpdate properties no longer exist on body objects. The solution suggested is to remove references to those properties.

I'm not in a position to be able to test this, but you could try updating the createBody method of your floor class as follows:

public static function createBody(name:String /*,graphic:DisplayObject=null*/):Body {
    var xret:BodyPair = lookup(name);
    //if(graphic==null) return xret.body.copy();

    var ret:Body = xret.body.copy();
    //graphic.x = graphic.y = 0;
    //graphic.rotation = 0;
    //var bounds:Rectangle = graphic.getBounds(graphic);
    //var offset:Vec2 = Vec2.get(bounds.x-xret.anchor.x, bounds.y-xret.anchor.y);

    //ret.graphic = graphic;
    /*
    ret.graphicUpdate = function(b:Body):void {
        var gp:Vec2 = b.localToWorld(offset);
        graphic.x = gp.x;
        graphic.y = gp.y;
        graphic.rotation = (b.rotation*180/Math.PI)%360;
    }   
    */
    return ret;
}