Class Obstacle

java.lang.Object
edu.cornell.gdiac.physics2.Obstacle
Direct Known Subclasses:
BoxObstacle, CapsuleObstacle, PolygonObstacle, WheelObstacle

public abstract class Obstacle extends Object
Base model class to support collisions.

This class represents a single body with its attached fixtures, simplifying the creation of a Box2d object. It also encapsulates information about the physics scale (e.g. the meaning of 1 Box2d unit in pixels) to simplify drawing. Finally, it has some simple drawing methods primarily intended to be used in debugging.

This abstract class has no Body or Shape information and should never be instantiated directly. Instead, you should instantiate an obstacle of a specific shape. This class only exists to unify common functionality.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected com.badlogic.gdx.physics.box2d.Body
    The physics body for Box2d.
    protected com.badlogic.gdx.physics.box2d.BodyDef
    Stores the body information for this shape
    protected com.badlogic.gdx.math.Vector2
    A cache value for when the user wants to access the center of mass
    static float
    The default physics units
    protected com.badlogic.gdx.physics.box2d.FixtureDef
    Stores the fixture information for this shape
    protected com.badlogic.gdx.physics.box2d.MassData
    The mass data of this shape (which may override the fixture)
    protected boolean
    Whether or not to use the custom mass data
    protected Path2
    The shape outline for drawing
    protected com.badlogic.gdx.math.Vector2
    A cache value for when the user wants to access the body position
    protected com.badlogic.gdx.math.Affine2
    An affine transform for drawing the path
    protected float
    The physics units for drawing
    protected com.badlogic.gdx.math.Vector2
    A cache value for when the user wants to access the linear velocity
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates a new physics object at the origin.
    protected
    Obstacle(float x, float y)
    Creates a new physics object
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    activatePhysics(com.badlogic.gdx.physics.box2d.World world)
    Creates the physics Body(s) for this object, adding them to the world.
    protected abstract void
    Creates new fixtures for this body, defining the shape
    void
    deactivatePhysics(com.badlogic.gdx.physics.box2d.World world)
    Destroys the physics Body(s) of this object if applicable, removing them from the world.
    void
    Draws a wireframe of this physics object.
    void
    draw(SpriteBatch batch, com.badlogic.gdx.graphics.Color color)
    Draws a wireframe of this physics object.
    void
    draw(SpriteBatch batch, com.badlogic.gdx.graphics.Color color, com.badlogic.gdx.math.Affine2 affine)
    Draws a wireframe of this physics object.
    void
    draw(SpriteBatch batch, com.badlogic.gdx.math.Affine2 affine)
    Draws a wireframe of this physics object.
    float
    Returns the angle of rotation for this body (about the center).
    float
    Returns the angular damping for this body.
    float
    Returns the angular velocity for this physics body
    com.badlogic.gdx.physics.box2d.Body
    Returns the Box2d body for this object.
    com.badlogic.gdx.physics.box2d.BodyDef.BodyType
    Returns the body type for Box2d physics
    com.badlogic.gdx.math.Vector2
    Returns the center of mass of this body
    float
    Returns the density of this body
    com.badlogic.gdx.physics.box2d.Filter
    Returns the filter data for this object (or null if there is none)
    float
    Returns the friction coefficient of this body
    float
    Returns the gravity scale to apply to this body
    float
    Returns the rotational inertia of this body
    float
    Returns the linear damping for this body.
    com.badlogic.gdx.math.Vector2
    Returns the linear velocity for this physics body
    float
    Returns the mass of this body
    Returns the physics object tag.
    Returns an outline of the obstacle in drawing space The outline will be scaled according the physics units of this obstacle.
    float
    Returns the physics units for this obstacle.
    com.badlogic.gdx.math.Vector2
    Returns the current position for this physics body
    float
    Returns the restitution of this body
    Returns the attached user data.
    float
    Returns the x-velocity for this physics body
    float
    Returns the y-velocity for this physics body
    float
    Returns the x-coordinate for this physics body
    float
    Returns the y-coordinate for this physics body
    boolean
    Returns true if the body is active
    boolean
    Returns true if the body is awake
    boolean
    Returns true if this body is a bullet
    boolean
    Returns true if the shape information must be updated.
    boolean
    Returns true if this body be prevented from rotating
    boolean
    Returns true if our object has been flagged for garbage collection
    boolean
    Returns true if this object is a sensor.
    boolean
    Returns false if this body should never fall asleep
    void
    markDirty(boolean value)
    Sets whether the shape information must be updated.
    void
    markRemoved(boolean value)
    Sets whether our object has been flagged for garbage collection
    protected abstract void
    Releases the fixtures for this body, reseting the shape
    void
    Resets this body to use the mass computed from the its shape and density
    void
    setActive(boolean value)
    Sets whether the body is active
    void
    setAngle(float value)
    Sets the angle of rotation for this body (about the center).
    void
    setAngularDamping(float value)
    Sets the angular damping for this body.
    void
    setAngularVelocity(float value)
    Sets the angular velocity for this physics body
    void
    setAwake(boolean value)
    Sets whether the body is awake
    protected void
    setBodyState(com.badlogic.gdx.physics.box2d.Body body)
    Copies the state from the given body to the body def.
    void
    setBodyType(com.badlogic.gdx.physics.box2d.BodyDef.BodyType value)
    Sets the body type for Box2d physics
    void
    setBullet(boolean value)
    Sets whether this body is a bullet
    void
    setCentroid(com.badlogic.gdx.math.Vector2 value)
    Sets the center of mass for this physics body
    void
    setDensity(float value)
    Sets the density of this body
    void
    setFilterData(com.badlogic.gdx.physics.box2d.Filter value)
    Sets the filter data for this object
    void
    setFixedRotation(boolean value)
    Sets whether this body be prevented from rotating
    void
    setFriction(float value)
    Sets the friction coefficient of this body
    void
    setGravityScale(float value)
    Sets the gravity scale to apply to this body
    void
    setInertia(float value)
    Sets the rotational inertia of this body
    void
    setLinearDamping(float value)
    Sets the linear damping for this body.
    void
    setLinearVelocity(com.badlogic.gdx.math.Vector2 value)
    Sets the linear velocity for this physics body
    void
    setMass(float value)
    Sets the mass of this body
    void
    setName(String value)
    Sets the physics object tag.
    void
    setPhysicsUnits(float units)
    Sets the physics units for this obstacle.
    void
    setPosition(float x, float y)
    Sets the current position for this physics body
    void
    setPosition(com.badlogic.gdx.math.Vector2 value)
    Sets the current position for this physics body
    void
    setRestitution(float value)
    Sets the restitution of this body
    void
    setSensor(boolean value)
    Sets whether this object is a sensor.
    void
    setSleepingAllowed(boolean value)
    Sets whether the body should ever fall asleep
    void
    Sets the attached user data.
    void
    setVX(float value)
    Sets the x-velocity for this physics body
    void
    setVY(float value)
    Sets the y-velocity for this physics body
    void
    setX(float value)
    Sets the x-coordinate for this physics body
    void
    setY(float value)
    Sets the y-coordinate for this physics body
    void
    update(float delta)
    Updates the object's physics state (NOT GAME LOGIC).

    Methods inherited from class java.lang.Object

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

    • DEFAULT_UNITS

      public static float DEFAULT_UNITS
      The default physics units
    • bodyinfo

      protected com.badlogic.gdx.physics.box2d.BodyDef bodyinfo
      Stores the body information for this shape
    • fixture

      protected com.badlogic.gdx.physics.box2d.FixtureDef fixture
      Stores the fixture information for this shape
    • massdata

      protected com.badlogic.gdx.physics.box2d.MassData massdata
      The mass data of this shape (which may override the fixture)
    • masseffect

      protected boolean masseffect
      Whether or not to use the custom mass data
    • body

      protected com.badlogic.gdx.physics.box2d.Body body
      The physics body for Box2d.
    • units

      protected float units
      The physics units for drawing
    • outline

      protected Path2 outline
      The shape outline for drawing
    • transform

      protected com.badlogic.gdx.math.Affine2 transform
      An affine transform for drawing the path
    • positionCache

      protected com.badlogic.gdx.math.Vector2 positionCache
      A cache value for when the user wants to access the body position
    • velocityCache

      protected com.badlogic.gdx.math.Vector2 velocityCache
      A cache value for when the user wants to access the linear velocity
    • centroidCache

      protected com.badlogic.gdx.math.Vector2 centroidCache
      A cache value for when the user wants to access the center of mass
  • Constructor Details

    • Obstacle

      protected Obstacle()
      Creates a new physics object at the origin.
    • Obstacle

      protected Obstacle(float x, float y)
      Creates a new physics object
      Parameters:
      x - Initial x position in world coordinates
      y - Initial y position in world coordinates
  • Method Details

    • getBody

      public com.badlogic.gdx.physics.box2d.Body getBody()
      Returns the Box2d body for this object.

      You use this body to add joints and apply forces.

      Returns:
      the Box2d body for this object.
    • getBodyType

      public com.badlogic.gdx.physics.box2d.BodyDef.BodyType getBodyType()
      Returns the body type for Box2d physics

      If you want to lock a body in place (e.g. a platform) set this value to STATIC. KINEMATIC allows the object to move (and some limited collisions), but ignores external forces (e.g. gravity). DYNAMIC makes this is a full-blown physics object.

      Returns:
      the body type for Box2d physics
    • setBodyType

      public void setBodyType(com.badlogic.gdx.physics.box2d.BodyDef.BodyType value)
      Sets the body type for Box2d physics

      If you want to lock a body in place (e.g. a platform) set this value to STATIC. KINEMATIC allows the object to move (and some limited collisions), but ignores external forces (e.g. gravity). DYNAMIC makes this is a full-blown physics object.

      Parameters:
      value - the body type for Box2d physics
    • getPosition

      public com.badlogic.gdx.math.Vector2 getPosition()
      Returns the current position for this physics body

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

      Returns:
      the current position for this physics body
    • setPosition

      public void setPosition(com.badlogic.gdx.math.Vector2 value)
      Sets the current position for this physics body

      This method does not keep a reference to the parameter.

      Parameters:
      value - the current position for this physics body
    • setPosition

      public void setPosition(float x, float y)
      Sets the current position for this physics body
      Parameters:
      x - the x-coordinate for this physics body
      y - the y-coordinate for this physics body
    • getX

      public float getX()
      Returns the x-coordinate for this physics body
      Returns:
      the x-coordinate for this physics body
    • setX

      public void setX(float value)
      Sets the x-coordinate for this physics body
      Parameters:
      value - the x-coordinate for this physics body
    • getY

      public float getY()
      Returns the y-coordinate for this physics body
      Returns:
      the y-coordinate for this physics body
    • setY

      public void setY(float value)
      Sets the y-coordinate for this physics body
      Parameters:
      value - the y-coordinate for this physics body
    • getAngle

      public float getAngle()
      Returns the angle of rotation for this body (about the center).

      The value returned is in radians.

      Returns:
      the angle of rotation for this body
    • setAngle

      public void setAngle(float value)
      Sets the angle of rotation for this body (about the center).
      Parameters:
      value - the angle of rotation for this body (in radians)
    • getLinearVelocity

      public com.badlogic.gdx.math.Vector2 getLinearVelocity()
      Returns the linear velocity for this physics body

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

      Returns:
      the linear velocity for this physics body
    • setLinearVelocity

      public void setLinearVelocity(com.badlogic.gdx.math.Vector2 value)
      Sets the linear velocity for this physics body

      This method does not keep a reference to the parameter.

      Parameters:
      value - the linear velocity for this physics body
    • getVX

      public float getVX()
      Returns the x-velocity for this physics body
      Returns:
      the x-velocity for this physics body
    • setVX

      public void setVX(float value)
      Sets the x-velocity for this physics body
      Parameters:
      value - the x-velocity for this physics body
    • getVY

      public float getVY()
      Returns the y-velocity for this physics body
      Returns:
      the y-velocity for this physics body
    • setVY

      public void setVY(float value)
      Sets the y-velocity for this physics body
      Parameters:
      value - the y-velocity for this physics body
    • getAngularVelocity

      public float getAngularVelocity()
      Returns the angular velocity for this physics body

      The rate of change is measured in radians per step.

      Returns:
      the angular velocity for this physics body
    • setAngularVelocity

      public void setAngularVelocity(float value)
      Sets the angular velocity for this physics body
      Parameters:
      value - the angular velocity for this physics body (in radians)
    • isActive

      public boolean isActive()
      Returns true if the body is active

      An inactive body not participate in collision or dynamics. This state is similar to sleeping except the body will not be woken by other bodies and the body's fixtures will not be placed in the broad-phase. This means the body will not participate in collisions, ray casts, etc.

      Returns:
      true if the body is active
    • setActive

      public void setActive(boolean value)
      Sets whether the body is active

      An inactive body not participate in collision or dynamics. This state is similar to sleeping except the body will not be woken by other bodies and the body's fixtures will not be placed in the broad-phase. This means the body will not participate in collisions, ray casts, etc.

      Parameters:
      value - whether the body is active
    • isAwake

      public boolean isAwake()
      Returns true if the body is awake

      An sleeping body is one that has come to rest and the physics engine has decided to stop simulating it to save CPU cycles. If a body is awake and collides with a sleeping body, then the sleeping body wakes up. Bodies will also wake up if a joint or contact attached to them is destroyed. You can also wake a body manually.

      Returns:
      true if the body is awake
    • setAwake

      public void setAwake(boolean value)
      Sets whether the body is awake

      An sleeping body is one that has come to rest and the physics engine has decided to stop simulating it to save CPU cycles. If a body is awake and collides with a sleeping body, then the sleeping body wakes up. Bodies will also wake up if a joint or contact attached to them is destroyed. You can also wake a body manually.

      Parameters:
      value - whether the body is awake
    • isSleepingAllowed

      public boolean isSleepingAllowed()
      Returns false if this body should never fall asleep

      An sleeping body is one that has come to rest and the physics engine has decided to stop simulating it to save CPU cycles. If a body is awake and collides with a sleeping body, then the sleeping body wakes up. Bodies will also wake up if a joint or contact attached to them is destroyed. You can also wake a body manually.

      Returns:
      false if this body should never fall asleep
    • setSleepingAllowed

      public void setSleepingAllowed(boolean value)
      Sets whether the body should ever fall asleep

      An sleeping body is one that has come to rest and the physics engine has decided to stop simulating it to save CPU cycles. If a body is awake and collides with a sleeping body, then the sleeping body wakes up. Bodies will also wake up if a joint or contact attached to them is destroyed. You can also wake a body manually.

      Parameters:
      value - whether the body should ever fall asleep
    • isBullet

      public boolean isBullet()
      Returns true if this body is a bullet

      By default, Box2d uses continuous collision detection (CCD) to prevent dynamic bodies from tunneling through static bodies. Normally CCD is not used between dynamic bodies. This is done to keep performance reasonable. In some game scenarios you need dynamic bodies to use CCD. For example, you may want to shoot a high speed bullet at a stack of dynamic bricks. Without CCD, the bullet might tunnel through the bricks.

      Fast moving objects in Box2d can be labeled as bullets. Bullets will perform CCD with both static and dynamic bodies. You should decide what bodies should be bullets based on your game design.

      Returns:
      true if this body is a bullet
    • setBullet

      public void setBullet(boolean value)
      Sets whether this body is a bullet

      By default, Box2d uses continuous collision detection (CCD) to prevent dynamic bodies from tunneling through static bodies. Normally CCD is not used between dynamic bodies. This is done to keep performance reasonable. In some game scenarios you need dynamic bodies to use CCD. For example, you may want to shoot a high speed bullet at a stack of dynamic bricks. Without CCD, the bullet might tunnel through the bricks.

      Fast moving objects in Box2d can be labeled as bullets. Bullets will perform CCD with both static and dynamic bodies. You should decide what bodies should be bullets based on your game design.

      Parameters:
      value - whether this body is a bullet
    • isFixedRotation

      public boolean isFixedRotation()
      Returns true if this body be prevented from rotating

      This is very useful for characters that should remain upright.

      Returns:
      true if this body be prevented from rotating
    • setFixedRotation

      public void setFixedRotation(boolean value)
      Sets whether this body be prevented from rotating

      This is very useful for characters that should remain upright.

      Parameters:
      value - whether this body be prevented from rotating
    • getGravityScale

      public float getGravityScale()
      Returns the gravity scale to apply to this body

      This allows isolated objects to float. Be careful with this, since increased gravity can decrease stability.

      Returns:
      the gravity scale to apply to this body
    • setGravityScale

      public void setGravityScale(float value)
      Sets the gravity scale to apply to this body

      This allows isolated objects to float. Be careful with this, since increased gravity can decrease stability.

      Parameters:
      value - the gravity scale to apply to this body
    • getLinearDamping

      public float getLinearDamping()
      Returns the linear damping for this body.

      Linear damping is use to reduce the linear velocity. Damping is different than friction because friction only occurs with contact. Damping is not a replacement for friction and the two effects should be used together.

      Damping parameters should be between 0 and infinity, with 0 meaning no damping, and infinity meaning full damping. Normally you will use a damping value between 0 and 0.1. Most people avoid linear damping because it makes bodies look floaty.

      Returns:
      the linear damping for this body.
    • setLinearDamping

      public void setLinearDamping(float value)
      Sets the linear damping for this body.

      Linear damping is use to reduce the linear velocity. Damping is different from friction because friction only occurs with contact. Damping is not a replacement for friction and the two effects should be used together.

      Damping parameters should be between 0 and infinity, with 0 meaning no damping, and infinity meaning full damping. Normally you will use a damping value between 0 and 0.1. Most people avoid linear damping because it makes bodies look floaty.

      Parameters:
      value - the linear damping for this body.
    • getAngularDamping

      public float getAngularDamping()
      Returns the angular damping for this body.

      Angular damping is use to reduce the angular velocity. Damping is different from friction because friction only occurs with contact. Damping is not a replacement for friction and the two effects should be used together.

      Damping parameters should be between 0 and infinity, with 0 meaning no damping, and infinity meaning full damping. Normally you will use a damping value between 0 and 0.1.

      Returns:
      the angular damping for this body.
    • setAngularDamping

      public void setAngularDamping(float value)
      Sets the angular damping for this body.

      Angular damping is use to reduce the angular velocity. Damping is different from friction because friction only occurs with contact. Damping is not a replacement for friction and the two effects should be used together.

      Damping parameters should be between 0 and infinity, with 0 meaning no damping, and infinity meaning full damping. Normally you will use a damping value between 0 and 0.1.

      Parameters:
      value - the angular damping for this body.
    • setBodyState

      protected void setBodyState(com.badlogic.gdx.physics.box2d.Body body)
      Copies the state from the given body to the body def.

      This is important if you want to save the state of the body before removing it from the world.

      Parameters:
      body - the body to copy
    • getDensity

      public float getDensity()
      Returns the density of this body

      The density is typically measured in usually in kg/m^2. The density can be zero or positive. You should generally use similar densities for all your fixtures. This will improve stacking stability.

      Returns:
      the density of this body
    • setDensity

      public void setDensity(float value)
      Sets the density of this body

      The density is typically measured in usually in kg/m^2. The density can be zero or positive. You should generally use similar densities for all your fixtures. This will improve stacking stability.

      Parameters:
      value - the density of this body
    • getFriction

      public float getFriction()
      Returns the friction coefficient of this body

      The friction parameter is usually set between 0 and 1, but can be any non-negative value. A friction value of 0 turns off friction and a value of 1 makes the friction strong. When the friction force is computed between two shapes, Box2d must combine the friction parameters of the two parent fixtures. This is done with the geometric mean.

      Returns:
      the friction coefficient of this body
    • setFriction

      public void setFriction(float value)
      Sets the friction coefficient of this body

      The friction parameter is usually set between 0 and 1, but can be any non-negative value. A friction value of 0 turns off friction and a value of 1 makes the friction strong. When the friction force is computed between two shapes, Box2d must combine the friction parameters of the two parent fixtures. This is done with the geometric mean.

      Parameters:
      value - the friction coefficient of this body
    • getRestitution

      public float getRestitution()
      Returns the restitution of this body

      Restitution is used to make objects bounce. The restitution value is usually set to be between 0 and 1. Consider dropping a ball on a table. A value of zero means the ball won't bounce. This is called an inelastic collision. A value of one means the ball's velocity will be exactly reflected. This is called a perfectly elastic collision.

      Returns:
      the restitution of this body
    • setRestitution

      public void setRestitution(float value)
      Sets the restitution of this body

      Restitution is used to make objects bounce. The restitution value is usually set to be between 0 and 1. Consider dropping a ball on a table. A value of zero means the ball won't bounce. This is called an inelastic collision. A value of one means the ball's velocity will be exactly reflected. This is called a perfectly elastic collision.

      Parameters:
      value - the restitution of this body
    • isSensor

      public boolean isSensor()
      Returns true if this object is a sensor.

      Sometimes game logic needs to know when two entities overlap yet there should be no collision response. This is done by using sensors. A sensor is an entity that detects collision but does not produce a response.

      Returns:
      true if this object is a sensor.
    • setSensor

      public void setSensor(boolean value)
      Sets whether this object is a sensor.

      Sometimes game logic needs to know when two entities overlap yet there should be no collision response. This is done by using sensors. A sensor is an entity that detects collision but does not produce a response.

      Parameters:
      value - whether this object is a sensor.
    • getFilterData

      public com.badlogic.gdx.physics.box2d.Filter getFilterData()
      Returns the filter data for this object (or null if there is none)

      Collision filtering allows you to prevent collision between fixtures. For example, say you make a character that rides a bicycle. You want the bicycle to collide with the terrain and the character to collide with the terrain, but you don't want the character to collide with the bicycle (because they must overlap). Box2d supports such collision filtering using categories and groups.

      Returns:
      the filter data for this object (or null if there is none)
    • setFilterData

      public void setFilterData(com.badlogic.gdx.physics.box2d.Filter value)
      Sets the filter data for this object

      Collision filtering allows you to prevent collision between fixtures. For example, say you make a character that rides a bicycle. You want the bicycle to collide with the terrain and the character to collide with the terrain, but you don't want the character to collide with the bicycle (because they must overlap). Box2d supports such collision filtering using categories and groups.

      A value of null removes all collision filters.

      Parameters:
      value - the filter data for this object
    • getCentroid

      public com.badlogic.gdx.math.Vector2 getCentroid()
      Returns the center of mass of this body

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

      Returns:
      the center of mass for this physics body
    • setCentroid

      public void setCentroid(com.badlogic.gdx.math.Vector2 value)
      Sets the center of mass for this physics body

      This method does not keep a reference to the parameter.

      Parameters:
      value - the center of mass for this physics body
    • getInertia

      public float getInertia()
      Returns the rotational inertia of this body

      For static bodies, the mass and rotational inertia are set to zero. When a body has fixed rotation, its rotational inertia is zero.

      Returns:
      the rotational inertia of this body
    • setInertia

      public void setInertia(float value)
      Sets the rotational inertia of this body

      For static bodies, the mass and rotational inertia are set to zero. When a body has fixed rotation, its rotational inertia is zero.

      Parameters:
      value - the rotational inertia of this body
    • getMass

      public float getMass()
      Returns the mass of this body

      The value is usually in kilograms.

      Returns:
      the mass of this body
    • setMass

      public void setMass(float value)
      Sets the mass of this body

      The value is usually in kilograms.

      Parameters:
      value - the mass of this body
    • resetMass

      public void resetMass()
      Resets this body to use the mass computed from the its shape and density
    • isRemoved

      public boolean isRemoved()
      Returns true if our object has been flagged for garbage collection

      A garbage collected object will be removed from the physics world at the next time step.

      Returns:
      true if our object has been flagged for garbage collection
    • markRemoved

      public void markRemoved(boolean value)
      Sets whether our object has been flagged for garbage collection

      A garbage collected object will be removed from the physics world at the next time step.

      Parameters:
      value - whether our object has been flagged for garbage collection
    • isDirty

      public boolean isDirty()
      Returns true if the shape information must be updated.

      Attributes tied to the geometry (and not just forces/position) must wait for collisions to complete before they are reset. Shapes (and their properties) are reset in the update method.

      Returns:
      true if the shape information must be updated.
    • markDirty

      public void markDirty(boolean value)
      Sets whether the shape information must be updated.

      Attributes tied to the geometry (and not just forces/position) must wait for collisions to complete before they are reset. Shapes (and their properties) are reset in the update method.

      Parameters:
      value - whether the shape information must be updated.
    • getPhysicsUnits

      public float getPhysicsUnits()
      Returns the physics units for this obstacle.

      The physics units are the number of pixels to associate with one Box2d unit. Because mass is a function of area in Box2d, we typically want the physics objects to be small. So we decouple that scale from the physics object. However, we must track the scale difference in order to draw the obstacle.

      Returns:
      the physics units for this obstacle.
    • setPhysicsUnits

      public void setPhysicsUnits(float units)
      Sets the physics units for this obstacle.

      The physics units are the number of pixels to associate with one Box2d unit. Because mass is a function of area in Box2d, we typically want the physics objects to be small. So we decouple that scale from the physics object. However, we must track the scale difference in order to draw the obstacle.

      Parameters:
      units - physics units for this obstacle
    • getOutline

      public Path2 getOutline()
      Returns an outline of the obstacle in drawing space The outline will be scaled according the physics units of this obstacle.
      Returns:
      an outline of the obstacle in drawing space
    • draw

      public void draw(SpriteBatch batch)
      Draws a wireframe of this physics object.

      The physics object will be drawn to the given sprite batch as a white wireframe, using the getPhysicsUnits() to properly scale the shape.

      Parameters:
      batch - the spritebatch to draw this object
    • draw

      public void draw(SpriteBatch batch, com.badlogic.gdx.graphics.Color color)
      Draws a wireframe of this physics object.

      The physics object will be drawn to the given sprite batch as a wireframe of the given color, using the getPhysicsUnits() to properly scale the shape.

      Parameters:
      batch - the spritebatch to draw this object
      color - the wireframe color
    • draw

      public void draw(SpriteBatch batch, com.badlogic.gdx.math.Affine2 affine)
      Draws a wireframe of this physics object.

      The physics object will be drawn to the given sprite batch as a white wireframe, using the getPhysicsUnits() to properly scale the shape. The affine transform will be applied to this scaled coordinate system.

      Parameters:
      batch - the spritebatch to draw this object
      affine - the transform to apply
    • draw

      public void draw(SpriteBatch batch, com.badlogic.gdx.graphics.Color color, com.badlogic.gdx.math.Affine2 affine)
      Draws a wireframe of this physics object.

      The physics object will be drawn to the given sprite batch as a wireframe of the given color, using the getPhysicsUnits() to properly scale the shape. The affine transform will be applied to this scaled coordinate system.

      Parameters:
      batch - the spritebatch to draw this object
      color - the wireframe color
      affine - the transform to apply
    • getName

      public String getName()
      Returns the physics object tag.

      A tag is a string attached to an object, in order to identify it in debugging.

      Returns:
      the physics object tag.
    • setName

      public void setName(String value)
      Sets the physics object tag.

      A tag is a string attached to an object, in order to identify it in debugging.

      Parameters:
      value - the physics object tag
    • getUserData

      public ObstacleData getUserData()
      Returns the attached user data.

      While box2d bodies typically have Obstacle objects as their user data, sometimes we want to use other user data instead. If this value is null, then the body will default to the obstacle itself.

      Returns:
      the attached user data.
    • setUserData

      public void setUserData(ObstacleData value)
      Sets the attached user data.

      While box2d bodies typically have Obstacle objects as their user data, sometimes we want to use other user data instead. If this value is null, then the body will default to the obstacle itself.

      Parameters:
      value - the attached user data.
    • activatePhysics

      public boolean activatePhysics(com.badlogic.gdx.physics.box2d.World world)
      Creates the physics Body(s) for this object, adding them to the world.

      Implementations of this method should NOT retain a reference to World. That is a tight coupling that we should avoid.

      Parameters:
      world - Box2d world to store body
      Returns:
      true if object allocation succeeded
    • deactivatePhysics

      public void deactivatePhysics(com.badlogic.gdx.physics.box2d.World world)
      Destroys the physics Body(s) of this object if applicable, removing them from the world.
      Parameters:
      world - Box2d world that stores body
    • createFixtures

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

      This is the primary method to override for custom physics objects

    • releaseFixtures

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

      This is the primary method to override for custom physics objects.

    • update

      public void update(float delta)
      Updates the object's physics state (NOT GAME LOGIC).

      This method is called AFTER the collision resolution state. Therefore, it should not be used to process actions or any other gameplay information. Its primary purpose is to adjust changes to the fixture, which have to take place after collision.

      If the obstacle has an associated ObstacleData, this method will also notify that object that an update has occurred.

      Parameters:
      delta - The time since the last call to update