Search code examples
box2deaseljscreatejs

Box2D & EaselJS, setTransform returns an error


I have the following code to manually set the position of a (dynamic) object in a Box2D world (drawn with the help of EaselJS). Unfortunately setTransform returns this error.

Uncaught TypeError: Cannot read property 'position' of undefined 

This is the code

// during drag and drop
if(mouseJoint & isMouseDown) {
    mouseJoint.SetTarget(new b2Vec2(mouseX, mouseY));
    var body = mouse.getBodyAtMouse();

    if(body != null) {
        body.SetAngularVelocity(0);
        body.SetAngle(0);
        body.SetTransform(b2Vec2(10,10), 0);
    }

    ...

Solution

  • Solved by using

    body.SetPosition(new b2Vec2(10,10));