public class CollisionBox extends Rectangle implements CollisionShape
Rectangle that allows for interpolation. Game
objects can use this class to move around the game world and retrieve the
appropriate rendering coordinates after interpolating between the previous
and current position.| Constructor and Description |
|---|
CollisionBox() |
CollisionBox(float x,
float y,
float width,
float height) |
CollisionBox(int id) |
CollisionBox(int id,
float x,
float y,
float width,
float height) |
| Modifier and Type | Method and Description |
|---|---|
void |
add(float x,
float y)
Adds components to the position of this
Shape |
<T extends Positionable> |
addPostionChangeListener(PositionChangeListener<T> listener)
Adds a
PositionChangeListener to be notified of coordinate
changes |
<T extends Sizeable> |
addSizeChangeListener(SizeChangeListener<T> listener)
Adds a
SizeChangeListener to be notified of size changes |
void |
draw(Graphics g)
Draws this shape using a
Graphics instance |
void |
fill(Graphics g)
Fills this shape using a
Graphics instance |
void |
forceTo(float x,
float y)
Sets the current x and y coordinate to the specified x and y and force updates the
rendering position to match
|
void |
forceTo(float x,
float y,
float width,
float height)
Sets the current bounds to the specified bounds and force updates the
rendering bounds to match
|
void |
forceTo(Rectangle rectangle) |
void |
forceToHeight(float height)
Sets the current height to the specified height and force updates the
rendering bounds to match
|
void |
forceToWidth(float width)
Sets the current width to the specified width and force updates the
rendering bounds to match
|
float |
getDistanceTo(Positionable positionable)
Returns this distance between this object's x,y coordinates and the
provided
Positionable's xy coordinates |
int |
getId()
Returns the unique id of this object
|
int |
getRenderHeight() |
float |
getRenderRotation() |
int |
getRenderWidth() |
int |
getRenderX()
Returns the render x coordinate of this object
|
int |
getRenderY()
Returns the render y coordinate of this object
|
Shape |
getShape()
Returns the underlying
Shape instance |
void |
interpolate(GameContainer gc,
float alpha)
Interpolate between the previous and current state
|
void |
moveTowards(float x,
float y,
float speed)
Moves this
Positionable towards a coordinate |
void |
moveTowards(Positionable positionable,
float speed)
Moves this
Positionable towards another Positionable |
void |
preUpdate()
This method needs to be called at the start of each frame
before any changes are made to this object
|
<T extends Positionable> |
removePositionChangeListener(PositionChangeListener<T> listener)
Removes a
PositionChangeListener to stop it being notified of
coordinate changes |
<T extends Sizeable> |
removeSizeChangeListener(SizeChangeListener<T> listener)
Removes a
SizeChangeListener to stop it being notified of size
changes |
void |
rotate(float degrees)
Rotates this
Shape by a specified amount of degrees with its
first point as the origin |
void |
rotateAround(float centerX,
float centerY,
float degrees)
Rotates this
Shape by a specified amount of degrees around a
specified point |
void |
scale(float scale)
Scales the radius of this shape.
|
void |
set(float x,
float y)
Sets the x and y coordinate of this object
|
Rectangle |
set(float x,
float y,
float width,
float height) |
void |
set(Rectangle rectangle) |
void |
set(com.badlogic.gdx.math.Vector2 position) |
void |
setCenter(float x,
float y)
Sets the center x,y coordinate of this object
|
void |
setCenterX(float x)
Sets the center x coordinate
|
void |
setCenterY(float y)
Sets the center y coordianate
|
Rectangle |
setHeight(float height) |
void |
setRadius(float radius)
Sets the radius of this shape.
|
void |
setRotation(float degrees)
Sets the rotation of this
Shape with its first point as the
origin |
void |
setRotationAround(float centerX,
float centerY,
float degrees)
Sets the rotation of this
Shape with a specified point as the
origin |
void |
setRotationAround(Point center,
float degrees)
Sets the current rotation of the shape around a center point
|
Rectangle |
setSize(float sizeXY) |
Rectangle |
setSize(float width,
float height) |
Rectangle |
setWidth(float width) |
void |
setX(float x)
Sets the x coordinate of this object
|
void |
setY(float y)
Sets the y coordinate of this object
|
void |
subtract(float x,
float y)
Subtracts components from the position of this
Shape |
java.lang.String |
toString() |
void |
update(GameContainer gc,
float delta)
Updates the game screen
|
contains, contains, contains, contains, contains, contains, copy, edgeIterator, equals, getCenterX, getCenterY, getDistanceTo, getDistanceTo, getHeight, getMaxX, getMaxY, getMinX, getMinY, getNumberOfSides, getPolygon, getRotation, getVertices, getWidth, getX, getY, hashCode, intersection, intersects, intersects, intersects, intersects, intersects, intersects, intersects, intersectsLineSegment, intersectsLineSegment, intersectsLineSegment, isCircle, lerp, translateintersectsclone, finalize, getClass, notify, notifyAll, wait, wait, waitcontains, contains, intersects, intersects, intersectsLineSegment, intersectsLineSegmentgetDistanceTo, getDistanceTo, getX, getYgetCenterX, getCenterY, getHeight, getMaxX, getMaxY, getMinX, getMinY, getWidthpublic CollisionBox()
public CollisionBox(int id)
public CollisionBox(float x,
float y,
float width,
float height)
public CollisionBox(int id,
float x,
float y,
float width,
float height)
public void preUpdate()
CollisionShapepreUpdate in interface CollisionShapepublic void update(GameContainer gc, float delta)
Updatableupdate in interface Updatablegc - The GameContainer of the gamedelta - The time in seconds since the last updatepublic void interpolate(GameContainer gc, float alpha)
Updatableinterpolate in interface Updatablealpha - The interpolation alpha valuepublic void draw(Graphics g)
ShapeGraphics instancedraw in class Rectangleg - The Graphics context to render withShape.draw(Graphics)public void fill(Graphics g)
ShapeGraphics instancepublic <T extends Positionable> void addPostionChangeListener(PositionChangeListener<T> listener)
PositionablePositionChangeListener to be notified of coordinate
changesaddPostionChangeListener in interface Positionablelistener - The PositionChangeListener to addPositionable.addPostionChangeListener(PositionChangeListener)public <T extends Positionable> void removePositionChangeListener(PositionChangeListener<T> listener)
PositionablePositionChangeListener to stop it being notified of
coordinate changesremovePositionChangeListener in interface Positionablelistener - The PositionChangeListener to removePositionable.removePositionChangeListener(PositionChangeListener)public <T extends Sizeable> void addSizeChangeListener(SizeChangeListener<T> listener)
SizeableSizeChangeListener to be notified of size changesaddSizeChangeListener in interface Sizeablelistener - The SizeChangeListener to addpublic <T extends Sizeable> void removeSizeChangeListener(SizeChangeListener<T> listener)
SizeableSizeChangeListener to stop it being notified of size
changesremoveSizeChangeListener in interface Sizeablelistener - The SizeChangeListener to removepublic void setRotation(float degrees)
ShapeShape with its first point as the
originsetRotation in interface ParallelogramsetRotation in class Rectangledegrees - The rotation in degreespublic void rotate(float degrees)
ShapeShape by a specified amount of degrees with its
first point as the originrotate in interface Parallelogramrotate in class Rectangledegrees - The rotation in degreespublic void rotateAround(float centerX,
float centerY,
float degrees)
ShapeShape by a specified amount of degrees around a
specified pointrotateAround in interface ParallelogramrotateAround in class RectanglecenterX - The origin/center x coordinatecenterY - The origin/center y coordinatedegrees - The rotation in degreespublic void setRotationAround(Point center, float degrees)
ParallelogramsetRotationAround in interface ParallelogramsetRotationAround in class Rectanglecenter - The center point to rotate arounddegrees - The rotation angle in degreespublic void setRotationAround(float centerX,
float centerY,
float degrees)
ShapeShape with a specified point as the
originsetRotationAround in class RectanglecenterX - The origin/center x coordinatecenterY - The origin/center y coordinatedegrees - The rotation in degreespublic float getDistanceTo(Positionable positionable)
PositionablePositionable's xy coordinatesgetDistanceTo in interface Positionablepositionable - The Positionable to retrieve the distance frompublic void forceTo(float x,
float y)
CollisionShapeforceTo in interface CollisionShapex - The x coordinate to sety - The y coordinate to setpublic void forceTo(float x,
float y,
float width,
float height)
x - The x coordinate to sety - The y coordinate to setwidth - The width to setheight - The height to setpublic void forceTo(Rectangle rectangle)
public void forceToWidth(float width)
width - The width to setpublic void forceToHeight(float height)
height - The height to setpublic void moveTowards(float x,
float y,
float speed)
PositionablePositionable towards a coordinatemoveTowards in interface Positionablex - The target x coordinatey - The target y coordinatespeed - The amount to move bypublic void moveTowards(Positionable positionable, float speed)
PositionablePositionable towards another PositionablemoveTowards in interface Positionablepositionable - The target Positionablespeed - The amount to move bypublic void add(float x,
float y)
ShapeShapepublic void subtract(float x,
float y)
ShapeShapepublic Rectangle set(float x, float y, float width, float height)
public void set(float x,
float y)
Shapeset in interface CollisionShapeset in class Rectanglex - The x coordinatey - The y coordinatepublic void setX(float x)
ShapesetX in interface PositionablesetX in class Rectanglex - The x coordinatepublic void setY(float y)
ShapesetY in interface PositionablesetY in class Rectangley - The y coordinatepublic void setCenter(float x,
float y)
Shapepublic void setCenterX(float x)
ShapesetCenterX in interface SizeablesetCenterX in class Rectanglex - The x coordinate of the shape's centerpublic void setCenterY(float y)
ShapesetCenterY in interface SizeablesetCenterY in class Rectangley - The y coordinate of the shape's centerpublic void setRadius(float radius)
Shapepublic void scale(float scale)
Shapepublic int getRenderX()
PositionablegetRenderX in interface Positionablepublic int getRenderY()
PositionablegetRenderY in interface Positionablepublic int getRenderWidth()
public int getRenderHeight()
public float getRenderRotation()
public int getId()
PositionablegetId in interface PositionablegetId in interface Sizeablepublic Shape getShape()
CollisionShapeShape instancegetShape in interface CollisionShape