Class PhysicsComponent

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.physics.components.PhysicsComponent

public class PhysicsComponent extends Component
Lets an entity be controlled by physics. Do not directly modify the position of a physics-enabled entity. Instead, use forces to move it.

Entities with a PhysicsComponent will fire "collisionStart" and "collisionEnd" events. See PhysicsContactListener

  • Constructor Details

    • PhysicsComponent

      public PhysicsComponent()
      Create a physics component with default settings.
    • PhysicsComponent

      public PhysicsComponent(PhysicsEngine engine)
      Create a physics component
      Parameters:
      engine - The physics engine to attach the component to
  • Method Details

    • setBodyType

      public PhysicsComponent setBodyType(com.badlogic.gdx.physics.box2d.BodyDef.BodyType bodyType)
      Set body type
      Parameters:
      bodyType - body type, default = dynamic
      Returns:
      self
    • getBody

      public com.badlogic.gdx.physics.box2d.Body getBody()
      Get the physics body.
      Returns:
      physics body if entity has been created, null otherwise.
    • create

      public void create()
      Description copied from class: Component
      Called when the entity is created and registered. Initial logic such as calls to GetComponent should be made here, not in the constructor which is called before an entity is finished.
      Overrides:
      create in class Component
    • earlyUpdate

      public void earlyUpdate()
      Entity position needs to be updated to match the new physics position. This should happen before other updates, which may use the new position.
      Overrides:
      earlyUpdate in class Component
    • dispose

      public void dispose()
      Description copied from class: Component
      Called when the component is disposed. Dispose of any internal resources here.
      Overrides:
      dispose in class Component
    • setEnabled

      public void setEnabled(boolean enabled)
      Description copied from class: Component
      Enable or disable the component. While disabled, a component does not run update() or earlyUpdate(). Other events inside the component may still fire. The component can still be disposed while disabled.
      Overrides:
      setEnabled in class Component
      Parameters:
      enabled - Should component be enabled