ios-lizard
ios-lizard

Reputation: 834

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);
    }

    ...

Upvotes: 0

Views: 853

Answers (2)

ios-lizard
ios-lizard

Reputation: 834

Solved by using

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

Upvotes: 2

iforce2d
iforce2d

Reputation: 8272

I'm no JS guru, but I suspect you need to use 'new b2Vec2' instead of just 'b2Vec2', in the same way as you have for the SetTarget call.

Upvotes: 0

Related Questions