Class Obstacle
- Direct Known Subclasses:
BoxObstacle,CapsuleObstacle,PolygonObstacle,WheelObstacle
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
FieldsModifier and TypeFieldDescriptionprotected com.badlogic.gdx.physics.box2d.BodyThe physics body for Box2d.protected com.badlogic.gdx.physics.box2d.BodyDefStores the body information for this shapeprotected com.badlogic.gdx.math.Vector2A cache value for when the user wants to access the center of massstatic floatThe default physics unitsprotected com.badlogic.gdx.physics.box2d.FixtureDefStores the fixture information for this shapeprotected com.badlogic.gdx.physics.box2d.MassDataThe mass data of this shape (which may override the fixture)protected booleanWhether or not to use the custom mass dataprotected Path2The shape outline for drawingprotected com.badlogic.gdx.math.Vector2A cache value for when the user wants to access the body positionprotected com.badlogic.gdx.math.Affine2An affine transform for drawing the pathprotected floatThe physics units for drawingprotected com.badlogic.gdx.math.Vector2A cache value for when the user wants to access the linear velocity -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanactivatePhysics(com.badlogic.gdx.physics.box2d.World world) Creates the physics Body(s) for this object, adding them to the world.protected abstract voidCreates new fixtures for this body, defining the shapevoiddeactivatePhysics(com.badlogic.gdx.physics.box2d.World world) Destroys the physics Body(s) of this object if applicable, removing them from the world.voiddraw(SpriteBatch batch) Draws a wireframe of this physics object.voiddraw(SpriteBatch batch, com.badlogic.gdx.graphics.Color color) Draws a wireframe of this physics object.voiddraw(SpriteBatch batch, com.badlogic.gdx.graphics.Color color, com.badlogic.gdx.math.Affine2 affine) Draws a wireframe of this physics object.voiddraw(SpriteBatch batch, com.badlogic.gdx.math.Affine2 affine) Draws a wireframe of this physics object.floatgetAngle()Returns the angle of rotation for this body (about the center).floatReturns the angular damping for this body.floatReturns the angular velocity for this physics bodycom.badlogic.gdx.physics.box2d.BodygetBody()Returns the Box2d body for this object.com.badlogic.gdx.physics.box2d.BodyDef.BodyTypeReturns the body type for Box2d physicscom.badlogic.gdx.math.Vector2Returns the center of mass of this bodyfloatReturns the density of this bodycom.badlogic.gdx.physics.box2d.FilterReturns the filter data for this object (or null if there is none)floatReturns the friction coefficient of this bodyfloatReturns the gravity scale to apply to this bodyfloatReturns the rotational inertia of this bodyfloatReturns the linear damping for this body.com.badlogic.gdx.math.Vector2Returns the linear velocity for this physics bodyfloatgetMass()Returns the mass of this bodygetName()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.floatReturns the physics units for this obstacle.com.badlogic.gdx.math.Vector2Returns the current position for this physics bodyfloatReturns the restitution of this bodyReturns the attached user data.floatgetVX()Returns the x-velocity for this physics bodyfloatgetVY()Returns the y-velocity for this physics bodyfloatgetX()Returns the x-coordinate for this physics bodyfloatgetY()Returns the y-coordinate for this physics bodybooleanisActive()Returns true if the body is activebooleanisAwake()Returns true if the body is awakebooleanisBullet()Returns true if this body is a bulletbooleanisDirty()Returns true if the shape information must be updated.booleanReturns true if this body be prevented from rotatingbooleanReturns true if our object has been flagged for garbage collectionbooleanisSensor()Returns true if this object is a sensor.booleanReturns false if this body should never fall asleepvoidmarkDirty(boolean value) Sets whether the shape information must be updated.voidmarkRemoved(boolean value) Sets whether our object has been flagged for garbage collectionprotected abstract voidReleases the fixtures for this body, reseting the shapevoidResets this body to use the mass computed from the its shape and densityvoidsetActive(boolean value) Sets whether the body is activevoidsetAngle(float value) Sets the angle of rotation for this body (about the center).voidsetAngularDamping(float value) Sets the angular damping for this body.voidsetAngularVelocity(float value) Sets the angular velocity for this physics bodyvoidsetAwake(boolean value) Sets whether the body is awakeprotected voidsetBodyState(com.badlogic.gdx.physics.box2d.Body body) Copies the state from the given body to the body def.voidsetBodyType(com.badlogic.gdx.physics.box2d.BodyDef.BodyType value) Sets the body type for Box2d physicsvoidsetBullet(boolean value) Sets whether this body is a bulletvoidsetCentroid(com.badlogic.gdx.math.Vector2 value) Sets the center of mass for this physics bodyvoidsetDensity(float value) Sets the density of this bodyvoidsetFilterData(com.badlogic.gdx.physics.box2d.Filter value) Sets the filter data for this objectvoidsetFixedRotation(boolean value) Sets whether this body be prevented from rotatingvoidsetFriction(float value) Sets the friction coefficient of this bodyvoidsetGravityScale(float value) Sets the gravity scale to apply to this bodyvoidsetInertia(float value) Sets the rotational inertia of this bodyvoidsetLinearDamping(float value) Sets the linear damping for this body.voidsetLinearVelocity(com.badlogic.gdx.math.Vector2 value) Sets the linear velocity for this physics bodyvoidsetMass(float value) Sets the mass of this bodyvoidSets the physics object tag.voidsetPhysicsUnits(float units) Sets the physics units for this obstacle.voidsetPosition(float x, float y) Sets the current position for this physics bodyvoidsetPosition(com.badlogic.gdx.math.Vector2 value) Sets the current position for this physics bodyvoidsetRestitution(float value) Sets the restitution of this bodyvoidsetSensor(boolean value) Sets whether this object is a sensor.voidsetSleepingAllowed(boolean value) Sets whether the body should ever fall asleepvoidsetUserData(ObstacleData value) Sets the attached user data.voidsetVX(float value) Sets the x-velocity for this physics bodyvoidsetVY(float value) Sets the y-velocity for this physics bodyvoidsetX(float value) Sets the x-coordinate for this physics bodyvoidsetY(float value) Sets the y-coordinate for this physics bodyvoidupdate(float delta) Updates the object's physics state (NOT GAME LOGIC).
-
Field Details
-
DEFAULT_UNITS
public static float DEFAULT_UNITSThe default physics units -
bodyinfo
protected com.badlogic.gdx.physics.box2d.BodyDef bodyinfoStores the body information for this shape -
fixture
protected com.badlogic.gdx.physics.box2d.FixtureDef fixtureStores the fixture information for this shape -
massdata
protected com.badlogic.gdx.physics.box2d.MassData massdataThe mass data of this shape (which may override the fixture) -
masseffect
protected boolean masseffectWhether or not to use the custom mass data -
body
protected com.badlogic.gdx.physics.box2d.Body bodyThe physics body for Box2d. -
units
protected float unitsThe physics units for drawing -
outline
The shape outline for drawing -
transform
protected com.badlogic.gdx.math.Affine2 transformAn affine transform for drawing the path -
positionCache
protected com.badlogic.gdx.math.Vector2 positionCacheA cache value for when the user wants to access the body position -
velocityCache
protected com.badlogic.gdx.math.Vector2 velocityCacheA cache value for when the user wants to access the linear velocity -
centroidCache
protected com.badlogic.gdx.math.Vector2 centroidCacheA 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 coordinatesy- 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 physicsIf 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 physicsIf 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 bodyThis 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 bodyThis 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 bodyy- 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 bodyThis 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 bodyThis 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 bodyThe 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 activeAn 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 activeAn 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 awakeAn 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 awakeAn 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 asleepAn 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 asleepAn 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 bulletBy 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 bulletBy 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 rotatingThis 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 rotatingThis 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 bodyThis 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 bodyThis 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 bodyThe 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 bodyThe 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 bodyThe 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 bodyThe 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 bodyRestitution 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 bodyRestitution 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 objectCollision 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 bodyThis 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 bodyThis 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 bodyFor 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 bodyFor 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 bodyThe value is usually in kilograms.
- Returns:
- the mass of this body
-
setMass
public void setMass(float value) Sets the mass of this bodyThe 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 collectionA 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 collectionA 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
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
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
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 objectcolor- the wireframe color
-
draw
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 objectaffine- 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 objectcolor- the wireframe coloraffine- the transform to apply
-
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
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
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
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 shapeThis is the primary method to override for custom physics objects
-
releaseFixtures
protected abstract void releaseFixtures()Releases the fixtures for this body, reseting the shapeThis 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
-