Applying an image to linked objects

Hi, I was able to connect multiple objects to create a U shape to carry stuff, but I cannot apply an image or texture to this objects.

Normally I use this to create an object and apply an image to it:

bodyDef = new b2BodyDef();
bodyDef.fixedRotation = true;
bodyDef.position.x = 7;
bodyDef.position.y = 3;
var crate_width:Number = 4;
var crate_height:Number = 0.5;
boxDef = new b2PolygonDef();
boxDef.SetAsBox(crate_width/3, crate_height/3);
boxDef.density = 20.0;
boxDef.friction = 100;
boxDef.restitution = 0;
bodyDef.userData = new paddle();//this is the Sprite that has the image
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.SetMassFromShapes();
body.m_userData.id = "paddle";
addChild(bodyDef.userData);

//then I attach a mouse joint to this object
var mouse_joint:b2MouseJointDef = new b2MouseJointDef;
mouse_joint.body1 = m_world.GetGroundBody();
mouse_joint.body2 = body;
mouse_joint.target.Set(bodyDef.position.x, bodyDef.position.y);
mouse_joint.maxForce = 1000;
mouse_joint.timeStep = m_timeStep;
mouseJoint = m_world.CreateJoint(mouse_joint) as b2MouseJoint;

With this I create an object and apply a texture to it, and attach later a mouse joint to move this object with my mouse.

Now Im creating a group of objects that will create a U shaped object and I will attach it to my mouse:


bodyDef = new b2BodyDef();
bodyDef.position.Set(1, 3);
bodyDef.fixedRotation = true;
body = m_world.CreateBody(bodyDef);
for (var j=0; j<5; j++) {
for (var i=0; i<5; i++) {
if (maze[j][i]==1) {
boxDef = new b2PolygonDef();
boxDef.SetAsOrientedBox(0.5,0.5,new b2Vec2(i, j), 0);
boxDef.density=1.0;
boxDef.friction=0.5;
boxDef.restitution = 0.2;
body.CreateShape(boxDef);
}
}
}
body.SetMassFromShapes();
And then I use the same mousjoint to attach it to this object and it works, but how can I apply the texture to all the squares of this containter, I put it inside the for for each definition of boxdef and it doesnt work, or I do it at the end for the whole body def but its not showing (plus there is no right width and height since there is a hole in the middle of the shape), so how can I do this?

Thanks
Of course, the maze array is like this.

var maze:Array = [[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 1, 1, 1, 1]];

Thats how its a container.

Hope you can help, thanks
It would be easiest I guess to make a (single) specific graphic for your basket which shows the same shape. You can then add to the body just like you do with your other bodies.
Another option is to use the userdata of the shape. Each shape has a userdata reference as well, you can put a graphic here just as well as on the body. From there you could use the extents of the shape to size your graphic.

However, it will be a bit harder to figure out the position and rotation of the shape. At this time, I'm not sure of a convenient way to do that.

You could use flash's strengths to your advantage though. If you really want the graphics seperate per shape, I would suggest setting up a single movieclip as a container to attach to the body, inside it you would place seperate graphics relative to its 0,0 point and corresponding to the positions of the shapes. You could then set that graphic as the userdata for the shape( in case you need a reference for when/if you remove the shape later. )
Thanks for the reply, I ended up using one image for the whole shape, I just matched it with the object created from the mix of all the cubes.

Thanks.

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