Hi everybody!
I'm new in the magic world of box2D and I got stucked with this problem: I'm using the following function to update the position of the userdata to the position of the body itself.
I have these questions:
1) How can I also access the real body's variables within the for loop? For example: let's assume that within this loop, if the variable life is smaller than 15, I want to scale down the userdata dimension (this I can do) AND the real object as well (so that collisions happen with the small object). How can I handle that?
2) How can I destroy the userdata (or how can I get the shape pointer, given a certain body so that I can invoke DestroyShape on it?). For example: let's assume that within this loop, if the variable life is smaller or equal to 0, I want to remove the body (this I can do) AND the userdata as well (I used the work-around to place it out of the stage, but I'm sure there's a better way).
Thank you for your attention!
I'm new in the magic world of box2D and I got stucked with this problem: I'm using the following function to update the position of the userdata to the position of the body itself.
Code:
public function Update(e:Event):void {
the_world.Step(10, 1/30);
for (var bb:b2Body = the_world.m_bodyList; bb; bb = bb.m_next) {
if (bb.m_userData is Sprite) {
bb.m_userData.life--;
bb.m_userData.x = bb.GetPosition().x * 30;
bb.m_userData.y = bb.GetPosition().y * 30;
bb.m_userData.rotation = bb.GetAngle() * (180/Math.PI);
if(bb.m_userData.life < 15){
bb.m_userData.width=2*bb.m_userData.width/3;
bb.m_userData.height=bb.m_userData.width;
bb.m_userData.y -= p2m(100);
}
if(bb.m_userData.life<=0){
bb.m_userData.x = -100;
bb.m_userData.y = -100;
the_world.DestroyBody(bb);
}
}
}
}
the_world.Step(10, 1/30);
for (var bb:b2Body = the_world.m_bodyList; bb; bb = bb.m_next) {
if (bb.m_userData is Sprite) {
bb.m_userData.life--;
bb.m_userData.x = bb.GetPosition().x * 30;
bb.m_userData.y = bb.GetPosition().y * 30;
bb.m_userData.rotation = bb.GetAngle() * (180/Math.PI);
if(bb.m_userData.life < 15){
bb.m_userData.width=2*bb.m_userData.width/3;
bb.m_userData.height=bb.m_userData.width;
bb.m_userData.y -= p2m(100);
}
if(bb.m_userData.life<=0){
bb.m_userData.x = -100;
bb.m_userData.y = -100;
the_world.DestroyBody(bb);
}
}
}
}
I have these questions:
1) How can I also access the real body's variables within the for loop? For example: let's assume that within this loop, if the variable life is smaller than 15, I want to scale down the userdata dimension (this I can do) AND the real object as well (so that collisions happen with the small object). How can I handle that?
2) How can I destroy the userdata (or how can I get the shape pointer, given a certain body so that I can invoke DestroyShape on it?). For example: let's assume that within this loop, if the variable life is smaller or equal to 0, I want to remove the body (this I can do) AND the userdata as well (I used the work-around to place it out of the stage, but I'm sure there's a better way).
Thank you for your attention!