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 java.lang.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
Fields Modifier and Type Field Description com.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Body>
brokenBodies
the bodies that broke instrain(Contact, ContactImpulse)
com.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Fixture>
brokenFixtures
the fixtures that broke instrain(Contact, ContactImpulse)
com.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Joint>
brokenJoints
the joints that broke instrain(Joint, float)
static net.dermetfan.utils.Function<java.lang.Object,Breakable>
defaultUserDataAccessor
theuserDataAccessor
used by default -
Constructor Summary
Constructors Constructor Description Manager()
instantiates a newBreakable.Manager
Manager(net.dermetfan.utils.Function<java.lang.Object,Breakable> userDataAccessor)
instantiates a newBreakable.Manager
with the givenuserDataAccessor
-
Method Summary
Modifier and Type Method Description void
beginContact(com.badlogic.gdx.physics.box2d.Contact contact)
does nothingvoid
destroy()
actually destroys all bodies inbrokenBodies
and fixtures inbrokenFixtures
void
destroy(com.badlogic.gdx.physics.box2d.Body body)
void
destroy(com.badlogic.gdx.physics.box2d.Fixture fixture)
destroys the given fixture (and its body depending onBreakable.breakBodyWithoutFixtures
andBreakable.breakBody
)void
destroy(com.badlogic.gdx.physics.box2d.Joint joint)
void
endContact(com.badlogic.gdx.physics.box2d.Contact contact)
does nothingcom.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Body>
getBrokenBodies()
com.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Fixture>
getBrokenFixtures()
net.dermetfan.utils.Function<java.lang.Object,Breakable>
getUserDataAccessor()
void
postSolve(com.badlogic.gdx.physics.box2d.Contact contact, com.badlogic.gdx.physics.box2d.ContactImpulse impulse)
void
preSolve(com.badlogic.gdx.physics.box2d.Contact contact, com.badlogic.gdx.physics.box2d.Manifold oldManifold)
does nothingvoid
setUserDataAccessor(net.dermetfan.utils.Function<java.lang.Object,Breakable> userDataAccessor)
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)
static boolean
shouldBreak(Breakable breakable, com.badlogic.gdx.math.Vector2 reactionForce, float reactionTorque, com.badlogic.gdx.physics.box2d.Joint joint)
void
strain(com.badlogic.gdx.physics.box2d.Contact contact, com.badlogic.gdx.physics.box2d.ContactImpulse impulse)
void
strain(com.badlogic.gdx.physics.box2d.Joint joint, float delta)
void
strain(com.badlogic.gdx.physics.box2d.World world, float delta)
strains
all joints in the given worldMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
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
public static final net.dermetfan.utils.Function<java.lang.Object,Breakable> defaultUserDataAccessortheuserDataAccessor
used by default
-
-
Constructor Details
-
Manager
public Manager()instantiates a newBreakable.Manager
-
Manager
instantiates a newBreakable.Manager
with the givenuserDataAccessor
-
-
Method Details
-
destroy
public void destroy()actually destroys all bodies inbrokenBodies
and 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)strains
all 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 force
reactionTorque
- thereaction torque
joint
- 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.breakBodyWithoutFixtures
andBreakable.breakBody
)- Parameters:
fixture
- theFixture
to destroy
-
destroy
public void destroy(com.badlogic.gdx.physics.box2d.Body body)- Parameters:
body
- theBody
to destroy
-
destroy
public void destroy(com.badlogic.gdx.physics.box2d.Joint joint)- Parameters:
joint
- theJoint
to destroy
-
beginContact
public void beginContact(com.badlogic.gdx.physics.box2d.Contact contact)does nothing- Specified by:
beginContact
in 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:
preSolve
in 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:
postSolve
in interfacecom.badlogic.gdx.physics.box2d.ContactListener
-
endContact
public void endContact(com.badlogic.gdx.physics.box2d.Contact contact)does nothing- Specified by:
endContact
in 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
public void setUserDataAccessor(net.dermetfan.utils.Function<java.lang.Object,Breakable> userDataAccessor)- Parameters:
userDataAccessor
- theuserDataAccessor
to set
-