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