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 in strain(Contact, ContactImpulse)
    com.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Fixture> brokenFixtures
    the fixtures that broke in strain(Contact, ContactImpulse)
    com.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Joint> brokenJoints
    the joints that broke in strain(Joint, float)
    static net.dermetfan.utils.Function<java.lang.Object,​Breakable> defaultUserDataAccessor
    the userDataAccessor used by default
  • Constructor Summary

    Constructors
    Constructor Description
    Manager()
    instantiates a new Breakable.Manager
    Manager​(net.dermetfan.utils.Function<java.lang.Object,​Breakable> userDataAccessor)
    instantiates a new Breakable.Manager with the given userDataAccessor
  • Method Summary

    Modifier and Type Method Description
    void beginContact​(com.badlogic.gdx.physics.box2d.Contact contact)
    does nothing
    void destroy()
    actually destroys all bodies in brokenBodies and fixtures in brokenFixtures
    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 on Breakable.breakBodyWithoutFixtures and Breakable.breakBody)
    void destroy​(com.badlogic.gdx.physics.box2d.Joint joint)  
    void endContact​(com.badlogic.gdx.physics.box2d.Contact contact)
    does nothing
    com.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 nothing
    void 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)
    destroys/destroys all fixtures/bodies involved in the given Contact if they could not bear the given 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 world

    Methods 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> brokenFixtures
      the fixtures that broke in strain(Contact, ContactImpulse)
    • brokenBodies

      public final com.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Body> brokenBodies
      the bodies that broke in strain(Contact, ContactImpulse)
    • brokenJoints

      public final com.badlogic.gdx.utils.Array<com.badlogic.gdx.physics.box2d.Joint> brokenJoints
      the joints that broke in strain(Joint, float)
    • defaultUserDataAccessor

      public static final net.dermetfan.utils.Function<java.lang.Object,​Breakable> defaultUserDataAccessor
      the userDataAccessor used by default
  • Constructor Details

    • Manager

      public Manager()
      instantiates a new Breakable.Manager
    • Manager

      public Manager​(net.dermetfan.utils.Function<java.lang.Object,​Breakable> userDataAccessor)
      instantiates a new Breakable.Manager with the given userDataAccessor
  • Method Details

    • destroy

      public void destroy()
      actually destroys all bodies in brokenBodies and fixtures in brokenFixtures
    • strain

      public void strain​(com.badlogic.gdx.physics.box2d.Contact contact, com.badlogic.gdx.physics.box2d.ContactImpulse impulse)
      destroys/destroys all fixtures/bodies involved in the given Contact if they could not bear the given 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 - for Breakable.Callback.strained(Fixture, Breakable, Contact, ContactImpulse, float, float)
      impulse - for Breakable.Callback.strained(Fixture, Breakable, Contact, ContactImpulse, float, float)
      fixture - for Breakable.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 - the reaction force
      reactionTorque - the reaction 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 on Breakable.breakBodyWithoutFixtures and Breakable.breakBody)
      Parameters:
      fixture - the Fixture to destroy
    • destroy

      public void destroy​(com.badlogic.gdx.physics.box2d.Body body)
      Parameters:
      body - the Body to destroy
    • destroy

      public void destroy​(com.badlogic.gdx.physics.box2d.Joint joint)
      Parameters:
      joint - the Joint to destroy
    • beginContact

      public void beginContact​(com.badlogic.gdx.physics.box2d.Contact contact)
      does nothing
      Specified by:
      beginContact in interface com.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 interface com.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 interface com.badlogic.gdx.physics.box2d.ContactListener
    • endContact

      public void endContact​(com.badlogic.gdx.physics.box2d.Contact contact)
      does nothing
      Specified by:
      endContact in interface com.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

      public net.dermetfan.utils.Function<java.lang.Object,​Breakable> getUserDataAccessor()
      Returns:
      the userDataAccessor
    • setUserDataAccessor

      public void setUserDataAccessor​(net.dermetfan.utils.Function<java.lang.Object,​Breakable> userDataAccessor)
      Parameters:
      userDataAccessor - the userDataAccessor to set