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?)
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?)