Newbie problem with positioning objects

Ok so I'm sorry to have to post this, I have been doing searches of the forum and looking at the manual for a while now and honestly can't find the answer. I'm completely new to Box2D, please be kind...

From what I've read I understand that Box2D doesn't work in pixels, which is the only way I know how to work in Flash. I need to be able to position objects accurately or screen for a game I'm building. How on earth do I convert the box2D 'units' into something I can work with?

For example, I have a plain rectangular symbol [ PlainEdge() ] that I want to place at each of the four edges of my flash movie to form a sort of 'frame.' The game is 640 x 480 pixels in size. (Note: stageWidth and stageHeight are global constants with the values 640 and 480 respectively) Here is the code I am using to attempt to place my rectangle along the bottom of the screen:

var bottomSideDef:b2BodyDef = new b2BodyDef();
bottomSideDef.position.Set(0, stageHeight-15);

var bottomShape:b2PolygonDef = new b2PolygonDef();
bottomShape.SetAsBox(stageWidth/2, 7.5); //HALF width/height values
bottomShape.friction = 0.3;
bottomShape.density = 0; //Static object

//Add a sprite
bottomSideDef.userData = new PlainEdge();
bottomSideDef.userData.width = stageWidth;
bottomSideDef.userData.height = 15;
addChild(bottomSideDef.userData);

bottomSide = gameWorld.CreateBody(bottomSideDef);
bottomSide.CreateShape(bottomShape);
bottomSide.SetMassFromShapes();

Currently this is drawing the rectangle right at the top of the screen (rather than the bottom) and a little off to the left. The height is also considerably more than I expected, even though I am supplying half values to the SetAsBox function.

Can someone please point out where I'm going wrong? I am really sorry that I'm having to ask as basic a question as this, but I'm genuinely stumped here.


(Another minor issue I noticed is that the box that's appearing has rounded corners, even though the sprite I am using does not. Why is this?)
by default 1 meter (a box2d unit) is 30 pixels.

so your width height x and y should be divided by 30.

and during your update function where you take the positioning of box2d objects and update the positioning of the visual flash objects that represent them, you should multiply by 30.

that should take care of it.
Fantastic, thank you so much - I have it almost working now! The problem I have now, however, is that it seems to be drawing the rectangular sprite starting from the centre of the debug rectangle, rather than the top left hand corner.

Most of my code is copy-pasted from the Hello Box2D tutorial so I'm not sure why this is happening...

Here's my code to draw:

gameWorld.Step(m_timeStep, m_iterations);

// Go through body list and update sprite positions/rotations
for (var bb:b2Body = gameWorld.m_bodyList; bb; bb = bb.m_next){
if (bb.m_userData is Sprite){
bb.m_userData.x = bb.GetPosition().x * ratio;
bb.m_userData.y = bb.GetPosition().y * ratio;
bb.m_userData.rotation = bb.GetAngle() * (180/Math.PI);
}
}

Should I be subtracting half the width/height values to get the correct positions?
Aha! Never mind - I have fixed this one myself by manually repositioning the symbol so that it's origin was in the actual centre of the object, rather than the top left corner. If I'd known you could do that, my last project (non Box2D related) would have been a hell of a lot easier lol

Original thread: https://box2d.org/forum/viewtopic.php?t=4706