Class BoxObstacle
This model is designed for rectangular Box2d objects. Unless otherwise specified, the center of mass is the center of the rectangle.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected com.badlogic.gdx.physics.box2d.PolygonShapeShape information for this boxFields inherited from class edu.cornell.gdiac.physics2.Obstacle
body, bodyinfo, centroidCache, DEFAULT_UNITS, fixture, massdata, masseffect, outline, positionCache, transform, units, velocityCache -
Constructor Summary
ConstructorsConstructorDescriptionCreates a degnerate box at the origin.BoxObstacle(float width, float height) Creates a new box at the origin.BoxObstacle(float x, float y, float width, float height) Creates a new box object. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCreates new fixtures for this body, defining the shapecom.badlogic.gdx.math.Vector2Returns the dimensions of this boxfloatReturns the box heightfloatgetWidth()Returns the box widthprotected voidReleases the fixtures for this body, reseting the shapevoidsetDimension(float width, float height) Sets the dimensions of this boxvoidsetDimension(com.badlogic.gdx.math.Vector2 value) Sets the dimensions of this boxvoidsetHeight(float value) Sets the box heightvoidsetWidth(float value) Sets the box widthMethods inherited from class edu.cornell.gdiac.physics2.Obstacle
activatePhysics, deactivatePhysics, draw, draw, draw, draw, getAngle, getAngularDamping, getAngularVelocity, getBody, getBodyType, getCentroid, getDensity, getFilterData, getFriction, getGravityScale, getInertia, getLinearDamping, getLinearVelocity, getMass, getName, getOutline, getPhysicsUnits, getPosition, getRestitution, getUserData, getVX, getVY, getX, getY, isActive, isAwake, isBullet, isDirty, isFixedRotation, isRemoved, isSensor, isSleepingAllowed, markDirty, markRemoved, resetMass, setActive, setAngle, setAngularDamping, setAngularVelocity, setAwake, setBodyState, setBodyType, setBullet, setCentroid, setDensity, setFilterData, setFixedRotation, setFriction, setGravityScale, setInertia, setLinearDamping, setLinearVelocity, setMass, setName, setPhysicsUnits, setPosition, setPosition, setRestitution, setSensor, setSleepingAllowed, setUserData, setVX, setVY, setX, setY, update
-
Field Details
-
shape
protected com.badlogic.gdx.physics.box2d.PolygonShape shapeShape 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 unitsheight- 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 centery- Initial y position of the box centerwidth- The object width in physics unitsheight- The object width in physics units
-
-
Method Details
-
getDimension
public com.badlogic.gdx.math.Vector2 getDimension()Returns the dimensions of this boxThis 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 boxThis 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 boxheight- 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 shapeThis is the primary method to override for custom physics objects
- Specified by:
createFixturesin classObstacle
-
releaseFixtures
protected void releaseFixtures()Releases the fixtures for this body, reseting the shapeThis is the primary method to override for custom physics objects
- Specified by:
releaseFixturesin classObstacle
-