Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;

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
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? – justanotherhobbyist Jul 22 '12 at 8:18

Your Answer


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.