Update Animated Bodyshape

First: Love wck, it is giving me the intro to Box2d that I never had time for in the past.

I'm building a touch gui. The idea is that there is a "nebula" consisting of a bunch of identical BodyShapes. One of these shapes has "Focus" at a time, given by a MouseEvent handler. When the shape has focus, a child object extending based on the RadialGravity demo is added to it, making it the center(attractor?) of the nebula.

That much I've been able to handle, by extending ShapeBase and calling circle() in the shapes() override, along with some tweened properties and as3 Event handling.
What I'd like to add now is the ability to animate the scale(width,height) of the object. I've tried to do this as follows:

1. Change the type of BodyShape to "Animated"
2. Tween the location and scale of the shape.
3. call circle(newWidth/2); when the animation completes.

This seems to work fine for making the shape larger, but when I want to "blur" the object, following the same process, it doesn't seem to work. That is, the boundary remains at the larger scale.

What method to I need to call in order to update the computed "boundary"(fixture?) of my object?
In step 3 it sounds like you're constantly recreating new circles... are you destroying the previously created ones?

If I were doing this I would create the big circle / small circle animation (NOT extending BodyShape), then put the WCK objects on keyframes of that animation. When the animation plays the objects will automatically be created / destroyed as it hits the keyframes of the animation. If you make them all type = Animated they will move as you move the parent MovieClip (the animation one).

Either that or I'd just build the circle sensor as the maximum radius of the gravity, then override the gravity functionality so it does an additional distance check on each object if the gravity source is not in focus (not being pressed by the mouse).
I think I see where you are going. Essentially: in order to change the "size" of an object, it must be destroyed and recreated. I think I will just create tow subclasses - one dynamic, one animated and with gravity - and create/destroy them according to focus.
😀
FYI, I did end up figuring out a way to do this without removing an object from the display list. This function which I added to my class should be self-explainitory, please let me know if this is going to cause any problems in the future?

private function multFixt(mult:Number):void
{
if(b2fixtures) {
for(var i:int = 0; i < b2fixtures.length; ++i) {
b2fixtures[i].m_shape.m_radius *=mult;
}
}
}
Yeah I agree that's better. Box2D doesn't officially support resizing shapes but it's always worked anyway.
Hi,

I've been tackling the same issue. This code caused an error:

Code:
b2Def.polygon.SetAsBox(hx, hy)
fixture.m_shape = b2Def.polygon


But after looking at this post, I changed it to this which worked perfectly:

Code:
fixture.m_shape.SetAsBox(hx, hy)


I've no idea why one should work and not the other. The error didn't appear until the next time I tried to create a fixture using b2Def.polygon. I'm using the Alchemy Port but not WCK. If anyone can shed any light on this I would be interested but it's not urgent as I've solved my problem. I've mainly put this here for other people as it took me a little while to track this one down!

This was the stack.

TypeError: Error #1006: value is not a function.
at cmodule.Box2D::FSM__Z20b2Body_CreateFixturePvP8_AS3_Val/work()
at MethodInfo-2124()
at MethodInfo-1767()
at Box2DAS.Dynamics::b2Fixture()
at Box2DAS.Dynamics::b2Body/CreateFixture()

Tim

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