Hello!
I have this little situation:
I have a wck.BodyShape object with a shape.Box inside. On the wck.BodyShape I apply a pulley joint. Everything works well!
The idea is this:
I need to remove my wck.BodyShape object and reattach one in the exactly same place, with the same joint but with a much more smaller density, but without breaking the pulley mechanism... Any advice on how can I do this?
Thank you all,
Have Fun!
Is density the only thing you are changing? You don't have to destroy anything to change the density.
If you do need a new BodyShape, just remove the old one, add the new one, and keep a reference in code to the joint instance. The joint will remove itself once the first BodyShape is removed. With the joint, set myJoint.bodyShape1 = theNewBodyShape, then add it back to the world (addChild()). That should work if your BodyShape is on the end of the pulley that defines the joint. If not, you'll have to call "create()" on the joint instance that actually defines the joint.
There may be an easier way though if you describe what you're trying to do.
Hello and thank you very much for your time :)
Here is what I try to do:
1. yes, momentarily only changing the density will do the job. But I got a nasty issue (or don't know how to approach this) be cause I have a wck.BodyShape with a shapes.Box inside. If I set the density of 10 on my wck.BodyShape instance and density 1 set on my contained shapes.Box instance the engine will compute the "1" value and not 10 that I set on my parent wck.BodyShape instance. Is this normal? I am asking this because if I have 10 shapes.Box inside my wck.BodyShape will have to manually set the desired value of 10 on each instance. Is this only me?
2. ok, great! I can change the density on my wck.BodyShape :) but how do I do this? Simply create a class for my object, extend-it to wck.BodyShape and set the this.density to the desired value?
Thank you again,
Have Fun!
1. Yes this is normal.
2. Yeah, BodyShape has a density getter/setter that will update Box2D, but you don't necessarily have to create your own class...
I don't want to lead you down the wrong road - might be easier if you just post a screenshot of what you're trying to do. I'm scratching my head at 10 boxes in one symbol.
ok. basically the pulley starts with img A. I just want to change the size and the density of my black box in order to be lighter than the red box and so make the pulley reverse the position of mu boxes (img B.)
that's it. :)
thank you very, very much!
Ok, in this case why not just have two boxes in the BodyShape from the start (one small / one big). Make sure the joint connects to the smaller box, then remove the bigger one when you want the transition. Since the smaller box is always there, the joint is never destroyed.
The joint may stubbornly want to attach to the bigger box. In this case you can use the "target1Name" property to indicate the smaller box. You'll have to name the instances of both your smaller box and the combined boxes then set the property to something like:
MyTwoBoxes/MySmallerBox
The "/" tells the joint to look _inside_ the "MyTwoBoxes" instance for the "MySmallerBox" instance.