Class BoxObstacle

java.lang.Object
edu.cornell.gdiac.physics2.Obstacle
edu.cornell.gdiac.physics2.BoxObstacle

public class BoxObstacle extends Obstacle
Box-shaped model to support collisions.

This model is designed for rectangular Box2d objects. Unless otherwise specified, the center of mass is the center of the rectangle.

  • Field Details

    • shape

      protected com.badlogic.gdx.physics.box2d.PolygonShape shape
      Shape information for this box
  • Constructor Details

    • BoxObstacle

      public BoxObstacle()
      Creates a degnerate box at the origin.

      This box has no size, and so will not support collisions (e.g. it is only a body). You should setDimension(com.badlogic.gdx.math.Vector2) before activating this physics object.

    • BoxObstacle

      public BoxObstacle(float width, float height)
      Creates a new box at the origin.

      The size is expressed in physics units NOT pixels. In order for drawing to work properly, you MUST call Obstacle.setPhysicsUnits(float).

      Parameters:
      width - The object width in physics units
      height - The object width in physics units
    • BoxObstacle

      public BoxObstacle(float x, float y, float width, float height)
      Creates a new box object.

      The size is expressed in physics units NOT pixels. In order for drawing to work properly, you MUST call Obstacle.setPhysicsUnits(float).

      Parameters:
      x - Initial x position of the box center
      y - Initial y position of the box center
      width - The object width in physics units
      height - The object width in physics units
  • Method Details

    • getDimension

      public com.badlogic.gdx.math.Vector2 getDimension()
      Returns the dimensions of this box

      This method does NOT return a reference to the dimension vector. Changes to this vector will not affect the shape. However, it returns the same vector each time its is called, and so cannot be used as an allocator.

      Returns:
      the dimensions of this box
    • setDimension

      public void setDimension(com.badlogic.gdx.math.Vector2 value)
      Sets the dimensions of this box

      This method does not keep a reference to the parameter.

      Parameters:
      value - the dimensions of this box
    • setDimension

      public void setDimension(float width, float height)
      Sets the dimensions of this box
      Parameters:
      width - The width of this box
      height - The height of this box
    • getWidth

      public float getWidth()
      Returns the box width
      Returns:
      the box width
    • setWidth

      public void setWidth(float value)
      Sets the box width
      Parameters:
      value - the box width
    • getHeight

      public float getHeight()
      Returns the box height
      Returns:
      the box height
    • setHeight

      public void setHeight(float value)
      Sets the box height
      Parameters:
      value - the box height
    • createFixtures

      protected void createFixtures()
      Creates new fixtures for this body, defining the shape

      This is the primary method to override for custom physics objects

      Specified by:
      createFixtures in class Obstacle
    • releaseFixtures

      protected void releaseFixtures()
      Releases the fixtures for this body, reseting the shape

      This is the primary method to override for custom physics objects

      Specified by:
      releaseFixtures in class Obstacle