I need a way to detect when an object leaves the world boundaries, so that I remove points from the player.
Searching the wiki I found:
I'm new to AS3 and Box2D Scripting. Can anyone give me more detailed information on how to use this?
I basically want it to execute a "glo.bal.lives -= 1" whenever it is called.
I think that another possibility would be adding a sensor right under the game window, and using it to detect objects in contact.
*EDIT*
After some hours trying to do it I made no progress on the boundary option.
I have, however, made a wide sensor under the visible area and set is userData to "sensor". I also successfuly traced it using GetUserData().
Anyway, I couldn't use the b2ContactListener either, so I think that I just need some deeper instructions on the box2d listeners, which I couldn't find.
Thanks.
Searching the wiki I found:
Code:
You can implement a b2BoundaryListener that allows b2World to inform you when a body has gone outside the world AABB. When you get the callback, you shouldn't try to delete the body, instead you should mark the parent actor for deletion or error handling. After the physics time step, you should handle the event.
public class b2BoundaryListener
{
/// This is called for each body that leaves the world boundary.
/// @warning you can't modify the world inside this callback.
public virtual function Violation(body:b2Body) : void{};
};
You can then register an instance of your boundary listener with your world object. You should do this during world initialization.
myWorld.SetListener(myBoundaryListener);
// Use SetBoundaryListener() in newer versions of Box2D
public class b2BoundaryListener
{
/// This is called for each body that leaves the world boundary.
/// @warning you can't modify the world inside this callback.
public virtual function Violation(body:b2Body) : void{};
};
You can then register an instance of your boundary listener with your world object. You should do this during world initialization.
myWorld.SetListener(myBoundaryListener);
// Use SetBoundaryListener() in newer versions of Box2D
I'm new to AS3 and Box2D Scripting. Can anyone give me more detailed information on how to use this?
I basically want it to execute a "glo.bal.lives -= 1" whenever it is called.
I think that another possibility would be adding a sensor right under the game window, and using it to detect objects in contact.
*EDIT*
After some hours trying to do it I made no progress on the boundary option.
I have, however, made a wide sensor under the visible area and set is userData to "sensor". I also successfuly traced it using GetUserData().
Anyway, I couldn't use the b2ContactListener either, so I think that I just need some deeper instructions on the box2d listeners, which I couldn't find.
Thanks.