Package net.dermetfan.gdx.physics.box2d
Class Breakable.Manager
java.lang.Object
net.dermetfan.gdx.physics.box2d.Breakable.Manager
- All Implemented Interfaces:
com.badlogic.gdx.physics.box2d.ContactListener
- Enclosing class:
Breakable
public static class Breakable.Manager
extends Object
implements com.badlogic.gdx.physics.box2d.ContactListener
Manages the
Breakables of the Contacts it receives. Do not forget to set as ContactListener and to call destroy() after every world step.-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal com.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Body> the bodies that broke instrain(Contact, ContactImpulse)final com.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Fixture> the fixtures that broke instrain(Contact, ContactImpulse)final com.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Joint> the joints that broke instrain(Joint, float)theuserDataAccessorused by default -
Constructor Summary
ConstructorsConstructorDescriptionManager()instantiates a newBreakable.Managerinstantiates a newBreakable.Managerwith the givenuserDataAccessor -
Method Summary
Modifier and TypeMethodDescriptionvoidbeginContact(com.badlogic.gdx.physics.box2d.Contact contact) does nothingvoiddestroy()actually destroys all bodies inbrokenBodiesand fixtures inbrokenFixturesvoiddestroy(com.badlogic.gdx.physics.box2d.Body body) voiddestroy(com.badlogic.gdx.physics.box2d.Fixture fixture) destroys the given fixture (and its body depending onBreakable.breakBodyWithoutFixturesandBreakable.breakBody)voiddestroy(com.badlogic.gdx.physics.box2d.Joint joint) voidendContact(com.badlogic.gdx.physics.box2d.Contact contact) does nothingcom.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Body> com.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Fixture> voidpostSolve(com.badlogic.gdx.physics.box2d.Contact contact, com.badlogic.gdx.physics.box2d.ContactImpulse impulse) voidpreSolve(com.badlogic.gdx.physics.box2d.Contact contact, com.badlogic.gdx.physics.box2d.Manifold oldManifold) does nothingvoidsetUserDataAccessor(net.dermetfan.utils.Function<Object, Breakable> userDataAccessor) static booleanshouldBreak(Breakable breakable, float normalImpulse, float tangentImpulse, com.badlogic.gdx.physics.box2d.Contact contact, com.badlogic.gdx.physics.box2d.ContactImpulse impulse, com.badlogic.gdx.physics.box2d.Fixture fixture) static booleanshouldBreak(Breakable breakable, com.badlogic.gdx.math.Vector2 reactionForce, float reactionTorque, com.badlogic.gdx.physics.box2d.Joint joint) voidstrain(com.badlogic.gdx.physics.box2d.Contact contact, com.badlogic.gdx.physics.box2d.ContactImpulse impulse) voidstrain(com.badlogic.gdx.physics.box2d.Joint joint, float delta) voidstrain(com.badlogic.gdx.physics.box2d.World world, float delta) strainsall joints in the given world
-
Field Details
-
brokenFixtures
public final com.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Fixture> brokenFixturesthe fixtures that broke instrain(Contact, ContactImpulse) -
brokenBodies
public final com.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Body> brokenBodiesthe bodies that broke instrain(Contact, ContactImpulse) -
brokenJoints
public final com.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Joint> brokenJointsthe joints that broke instrain(Joint, float) -
defaultUserDataAccessor
theuserDataAccessorused by default
-
-
Constructor Details
-
Manager
public Manager()instantiates a newBreakable.Manager -
Manager
instantiates a newBreakable.Managerwith the givenuserDataAccessor
-
-
Method Details
-
destroy
public void destroy()actually destroys all bodies inbrokenBodiesand fixtures inbrokenFixtures -
strain
public void strain(com.badlogic.gdx.physics.box2d.Contact contact, com.badlogic.gdx.physics.box2d.ContactImpulse impulse) -
strain
public void strain(com.badlogic.gdx.physics.box2d.World world, float delta) strainsall joints in the given world -
strain
public void strain(com.badlogic.gdx.physics.box2d.Joint joint, float delta) -
shouldBreak
public static boolean shouldBreak(Breakable breakable, float normalImpulse, float tangentImpulse, com.badlogic.gdx.physics.box2d.Contact contact, com.badlogic.gdx.physics.box2d.ContactImpulse impulse, com.badlogic.gdx.physics.box2d.Fixture fixture) - Parameters:
contact- forBreakable.Callback.strained(Fixture, Breakable, Contact, ContactImpulse, float, float)impulse- forBreakable.Callback.strained(Fixture, Breakable, Contact, ContactImpulse, float, float)fixture- forBreakable.Callback.strained(Fixture, Breakable, Contact, ContactImpulse, float, float)- Returns:
- if the fixtures and bodies involved in the given contact should break under the given circumstances
-
shouldBreak
public static boolean shouldBreak(Breakable breakable, com.badlogic.gdx.math.Vector2 reactionForce, float reactionTorque, com.badlogic.gdx.physics.box2d.Joint joint) - Parameters:
reactionForce- thereaction forcereactionTorque- thereaction torquejoint- which circumstances to test- Returns:
- if the joint strained with the given values should break
-
destroy
public void destroy(com.badlogic.gdx.physics.box2d.Fixture fixture) destroys the given fixture (and its body depending onBreakable.breakBodyWithoutFixturesandBreakable.breakBody)- Parameters:
fixture- theFixtureto destroy
-
destroy
public void destroy(com.badlogic.gdx.physics.box2d.Body body) - Parameters:
body- theBodyto destroy
-
destroy
public void destroy(com.badlogic.gdx.physics.box2d.Joint joint) - Parameters:
joint- theJointto destroy
-
beginContact
public void beginContact(com.badlogic.gdx.physics.box2d.Contact contact) does nothing- Specified by:
beginContactin interfacecom.badlogic.gdx.physics.box2d.ContactListener
-
preSolve
public void preSolve(com.badlogic.gdx.physics.box2d.Contact contact, com.badlogic.gdx.physics.box2d.Manifold oldManifold) does nothing- Specified by:
preSolvein interfacecom.badlogic.gdx.physics.box2d.ContactListener
-
postSolve
public void postSolve(com.badlogic.gdx.physics.box2d.Contact contact, com.badlogic.gdx.physics.box2d.ContactImpulse impulse) - Specified by:
postSolvein interfacecom.badlogic.gdx.physics.box2d.ContactListener
-
endContact
public void endContact(com.badlogic.gdx.physics.box2d.Contact contact) does nothing- Specified by:
endContactin interfacecom.badlogic.gdx.physics.box2d.ContactListener
-
getBrokenFixtures
public com.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Fixture> getBrokenFixtures()- Returns:
- the
brokenFixtures
-
getBrokenBodies
public com.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Body> getBrokenBodies()- Returns:
- the
brokenBodies
-
getUserDataAccessor
- Returns:
- the
userDataAccessor
-
setUserDataAccessor
- Parameters:
userDataAccessor- theuserDataAccessorto set
-