I am doing the world objects loop wrong?

Hello!

I have started a Box2D project similar to the testbed example:

Main class, Test class and a TestLevel classes, where TestLevel extends Test and I instantiate new levels by
var Level1:Test = new TestLevel();

Everything works perfectly in debugDraw mode, but when I try to add some UserData and turn off the debug draw, the UserData mc gets stuck in the upper-left corner and nothing happens...

Here is how I try to update de userData mc's position/rotation:

Code: Select all

// Go through body list and update sprite positions/rotations
         for (var bb : b2Body = m_world.GetBodyList();bb;bb = bb.GetNext()) {
            if (bb.GetUserData() is MovieClip) {
               var sprite : MovieClip = bb.GetUserData() as MovieClip;
               sprite.x = bb.GetPosition().x * 30;
               sprite.y = bb.GetPosition().y * 30;
               sprite.rotation = bb.GetAngle() * (180 / Math.PI);
            }
         }


I get the feeling that this is were I do something wrong, as a trace(bb.GetUserData()) returns null...
I use Box2D 2.1a

Thank you for your time and efforts!
GF
Any sugestions? :)

Tnx,
GF
Have you got the differerence between definitions and bodies. A common mistake is to just set the defs userData, that has no effect after you have created a body from the def.
Right!

I was trying to add the userData to the b2FixtureDef instead of the b2BodyDef.
Now works fine!

I was wondering howcome I still got the code hint even when I do-it wrong? Like this:
fixture.userData....

Tnx a bunch!
GF
Several objects have user data fields. I personally, imagne using the fixture one for storing material properties, which might vary throughout the body.

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