Hi, im having a weird bug with box 2d in flash, every time I create a new object it doesnt matter what position do I give him, He always appears at the top left of the screen for less than a second and then it appears on the position that im giving him, is there a way to make this not happen?, anybody has seen this problem, Ive been looking around in forums and I dont know if there is anything similar.
Thanks.
this has been commented on before and its really simple. I'm assuming you are assigning a graphic that you create to a physics object and letting your update loop take care of moving those graphics for you. What happens is that for one frame the object is sitting at 0,0 because it hasn't been updated yet. A simple fix is to set the x and y values of your graphic when you create the body.
Ive been looking around this and for chaning the depth in the movie clip you would do swapDepths();, but for an box2d object that im creating how would you do it to make sure your main movie is in front and this on the back, since what I can do to hide this object from appearing on the top left is put an UI object in front to cover it, but this box2d objects are always in front of everything.
any ideas how to send them to the back?
thanks.
What do you mean by assigning it on the loop.
the way I create it is:
bodyDef = new b2BodyDef();
bodyDef.position.x = 6 + Math.random() * 5;
bodyDef.position.y = 0;
boxDef = new b2PolygonDef();
boxDef.SetAsBox(crate_width/3, crate_height/3);
boxDef.density = 1.0;
boxDef.friction = 0.5;
boxDef.restitution = 0.2;
bodyDef.userData = new crate();
trace("crate");
bodyDef.userData.width = crate_width * 2 * pixels_in_a_meter/3;
bodyDef.userData.height = crate_height * 2 * pixels_in_a_meter / 3;
body = m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.m_userData.id = "crate";
body.SetMassFromShapes();
addChild(bodyDef.userData);
on the loop im updating it, but in here im assigning a position different thatn 0,0, or what position are you talking about exactly,
thanks.
I got what you meant VengantMjolnir with the assignment on the loop, I just did the first assignment of position as soon as I create the object and it got fixed.
Thank,