Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

How can I interact with an object in box2d, I'm completely new to this so I have no clue what to do. The box is created like this:

bodyDef.type = b2Body.b2_dynamicBody;
fixDef.shape = new b2PolygonShape;

fixDef.shape.SetAsBox(0.5, 0.5); // Half-Width, Half-Height

bodyDef.position.x =  5;
bodyDef.position.y =  5;
world.CreateBody(bodyDef).CreateFixture(fixDef);

How can I change the x, y positions of that box, tried bodyDef.position.x--; but it returned "bodyDef is not defined". How do I access this?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

For moving here is SetTransform, for interacting MouseJoint. BodyDef is used to make creation of bodies easier, so it is used just in that function, you have to store value returned by CreateBody, and read documentation first.

share|improve this answer
    
Yeah I've looked trough the docs but there is no search function so it's kind of messy. Also I only started using this 10 hours ago, with 4-5 hours playing around and reading code. So basically I would do something like "player.SetTransform.position.x--;" if i store the value inside a player object? –  hustlerinc Jul 22 '12 at 8:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.