Class PhysicsEngine

java.lang.Object
com.deco2800.game.physics.PhysicsEngine
All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable

public class PhysicsEngine extends Object implements com.badlogic.gdx.utils.Disposable
Process game physics using the Box2D library. See the Box2D documentation for examples or use cases.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    PhysicsEngine(com.badlogic.gdx.physics.box2d.World world, GameTime timeSource)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    com.badlogic.gdx.physics.box2d.Body
    createBody(com.badlogic.gdx.physics.box2d.BodyDef bodyDef)
     
    com.badlogic.gdx.physics.box2d.Joint
    createJoint(com.badlogic.gdx.physics.box2d.JointDef jointDef)
     
    void
    destroyBody(com.badlogic.gdx.physics.box2d.Body body)
     
    void
    destroyJoint(com.badlogic.gdx.physics.box2d.Joint joint)
     
    void
     
    com.badlogic.gdx.physics.box2d.World
     
    boolean
    raycast(com.badlogic.gdx.math.Vector2 from, com.badlogic.gdx.math.Vector2 to, short layerMask, RaycastHit hit)
    Cast a ray in a straight line from one point to another, checking for a collision against colliders in the specified layers.
    boolean
    raycast(com.badlogic.gdx.math.Vector2 from, com.badlogic.gdx.math.Vector2 to, RaycastHit hit)
    Cast a ray in a straight line from one point to another, checking for a collision against any colliders.
    raycastAll(com.badlogic.gdx.math.Vector2 from, com.badlogic.gdx.math.Vector2 to)
    Cast a ray in a straight line from one point to another, checking for all collision against colliders in the specified layers.
    raycastAll(com.badlogic.gdx.math.Vector2 from, com.badlogic.gdx.math.Vector2 to, short layerMask)
    Cast a ray in a straight line from one point to another, checking for all collision against colliders in the specified layers.
    void
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PhysicsEngine

      public PhysicsEngine()
    • PhysicsEngine

      public PhysicsEngine(com.badlogic.gdx.physics.box2d.World world, GameTime timeSource)
  • Method Details

    • update

      public void update()
    • createBody

      public com.badlogic.gdx.physics.box2d.Body createBody(com.badlogic.gdx.physics.box2d.BodyDef bodyDef)
    • destroyBody

      public void destroyBody(com.badlogic.gdx.physics.box2d.Body body)
    • createJoint

      public com.badlogic.gdx.physics.box2d.Joint createJoint(com.badlogic.gdx.physics.box2d.JointDef jointDef)
    • destroyJoint

      public void destroyJoint(com.badlogic.gdx.physics.box2d.Joint joint)
    • getWorld

      public com.badlogic.gdx.physics.box2d.World getWorld()
    • raycast

      public boolean raycast(com.badlogic.gdx.math.Vector2 from, com.badlogic.gdx.math.Vector2 to, RaycastHit hit)
      Cast a ray in a straight line from one point to another, checking for a collision against any colliders.
      Parameters:
      from - The starting point of the ray.
      to - The end point of the ray.
      hit - The raycast result will be stored in this class
      Returns:
      true if a collider was hit, false otherwise.
    • raycast

      public boolean raycast(com.badlogic.gdx.math.Vector2 from, com.badlogic.gdx.math.Vector2 to, short layerMask, RaycastHit hit)
      Cast a ray in a straight line from one point to another, checking for a collision against colliders in the specified layers.
      Parameters:
      from - The starting point of the ray.
      to - The end point of the ray.
      hit - The hit of the closest collider will be stored in this.
      layerMask - The physics layer mask which specifies layers that can be hit. Other layers will be ignored.
      Returns:
      true if a collider was hit, false otherwise.
    • raycastAll

      public RaycastHit[] raycastAll(com.badlogic.gdx.math.Vector2 from, com.badlogic.gdx.math.Vector2 to)
      Cast a ray in a straight line from one point to another, checking for all collision against colliders in the specified layers.
      Parameters:
      from - The starting point of the ray.
      to - The end point of the ray.
      Returns:
      All hits made by the ray, unordered. Empty if no hits were made.
    • raycastAll

      public RaycastHit[] raycastAll(com.badlogic.gdx.math.Vector2 from, com.badlogic.gdx.math.Vector2 to, short layerMask)
      Cast a ray in a straight line from one point to another, checking for all collision against colliders in the specified layers.
      Parameters:
      from - The starting point of the ray.
      to - The end point of the ray.
      layerMask - The physics layer mask which specifies layers that can be hit. Other layers will be ignored.
      Returns:
      All hits made by the ray, unordered. Empty if no hits were made.
    • dispose

      public void dispose()
      Specified by:
      dispose in interface com.badlogic.gdx.utils.Disposable