public class CollisionBox extends Rectangle implements CollisionArea, PositionChangeListener<CollisionBox>, SizeChangeListener<CollisionBox>
Rectangle
that allows for interpolation. Game
objects can use this class to move around the game world and retrieve the
appropriate rendering coordinates during the render phase.geometry, positionChangeListeners, sizeChangeListeners
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 |
---|---|
<T extends Positionable> |
addPostionChangeListener(PositionChangeListener<T> listener)
Adds a
Positionable to be notified of coordinate
changes |
<T extends Sizeable> |
addSizeChangeListener(SizeChangeListener<T> listener)
Adds a
SizeChangeListener to be notified of size changes |
protected void |
clearPositionChangeListeners() |
protected void |
clearSizeChangeListeners() |
void |
dispose()
|
boolean |
equals(java.lang.Object o) |
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 x, y, width and height and force updates the
rendering state to match
|
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
|
int |
getId()
Returns the unique id of this object
|
int |
getRenderHeight()
Returns the render height of this object
|
int |
getRenderWidth()
Returns the render width of this object
|
int |
getRenderX()
Returns the render x coordinate of this object
|
int |
getRenderY()
Returns the render y coordinate of this object
|
int |
hashCode() |
void |
interpolate(float alpha)
Called during interpolate phase each interpolate()
|
boolean |
isInterpolateRequired() |
protected void |
notifyPositionChangeListeners() |
protected void |
notifySizeChangeListeners() |
void |
positionChanged(CollisionBox moved) |
void |
preUpdate()
Called at the start of each update() 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 |
sizeChanged(CollisionBox changed) |
java.lang.String |
toString() |
contains, contains, contains, contains, contains, copy, draw, edgeIterator, fill, getCenterX, getCenterY, getDistanceTo, getHeight, getMaxX, getMaxY, getMinX, getMinY, getNumberOfSides, getPolygon, getRotation, getVertices, getWidth, getX, getY, intersection, intersects, intersects, intersects, intersects, intersects, intersects, intersectsLineSegment, intersectsLineSegment, isCircle, lerp, rotate, rotateAround, scale, set, set, setCenter, setCenterX, setCenterY, setHeight, setRadius, setRotation, setRotationAround, setSize, setSize, setWidth, setX, setXY, setXY, setY, translate
add, clearPositionListeners, clearPositionListeners, clearSizeListeners, clearSizeListeners, getDistanceTo, intersects, moveTowards, moveTowards, notifyPositionListeners, notifyPositionListeners, notifySizeListeners, notifySizeListeners, removePositionListener, removePositionListener, removeSizeListener, removeSizeListener, setRotationAround, subtract
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
contains, contains, contains, getCenterX, getCenterY, getHeight, getMaxX, getMaxY, getMinX, getMinY, getNumberOfSides, getPolygon, getWidth, intersects, intersects, intersectsLineSegment, intersectsLineSegment, isCircle, scale, setCenter, setCenterX, setCenterY, setRadius
getDistanceTo, getDistanceTo, getX, getY, moveTowards, moveTowards, setX, setXY, setY
public 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 dispose()
Shape
public void forceTo(float x, float y)
CollisionObject
forceTo
in interface CollisionObject
x
- The x coordinate to sety
- The y coordinate to setpublic void forceTo(float x, float y, float width, float height)
CollisionArea
forceTo
in interface CollisionArea
x
- The x coordinate to sety
- The y coordinate to setpublic void forceToWidth(float width)
width
- The width to setpublic void forceToHeight(float height)
height
- The height to setpublic int getRenderWidth()
CollisionArea
getRenderWidth
in interface CollisionArea
public int getRenderHeight()
CollisionArea
getRenderHeight
in interface CollisionArea
public void preUpdate()
CollisionObject
preUpdate
in interface CollisionObject
preUpdate
in interface Interpolatable
public void interpolate(float alpha)
CollisionObject
interpolate
in interface CollisionObject
interpolate
in interface Interpolatable
alpha
- The alpha value between 0.0 and 1.0public int getRenderX()
CollisionObject
getRenderX
in interface CollisionObject
public int getRenderY()
CollisionObject
getRenderY
in interface CollisionObject
public int getId()
CollisionObject
getId
in interface CollisionObject
public void positionChanged(CollisionBox moved)
positionChanged
in interface PositionChangeListener<CollisionBox>
public void sizeChanged(CollisionBox changed)
sizeChanged
in interface SizeChangeListener<CollisionBox>
public <T extends Positionable> void addPostionChangeListener(PositionChangeListener<T> listener)
Positionable
Positionable
to be notified of coordinate
changesaddPostionChangeListener
in interface Positionable
addPostionChangeListener
in class Shape
listener
- The PositionChangeListener
to addPositionable.addPostionChangeListener(PositionChangeListener)
public <T extends Positionable> void removePositionChangeListener(PositionChangeListener<T> listener)
Positionable
PositionChangeListener
to stop it being notified of
coordinate changesremovePositionChangeListener
in interface Positionable
removePositionChangeListener
in class Shape
listener
- The PositionChangeListener
to removePositionable.removePositionChangeListener(PositionChangeListener)
public <T extends Sizeable> void addSizeChangeListener(SizeChangeListener<T> listener)
Sizeable
SizeChangeListener
to be notified of size changesaddSizeChangeListener
in interface Sizeable
addSizeChangeListener
in class Shape
listener
- The SizeChangeListener
to addpublic <T extends Sizeable> void removeSizeChangeListener(SizeChangeListener<T> listener)
Sizeable
SizeChangeListener
to stop it being notified of size
changesremoveSizeChangeListener
in interface Sizeable
removeSizeChangeListener
in class Shape
listener
- The SizeChangeListener
to removeprotected void notifyPositionChangeListeners()
notifyPositionChangeListeners
in class Shape
protected void clearPositionChangeListeners()
clearPositionChangeListeners
in class Shape
protected void notifySizeChangeListeners()
notifySizeChangeListeners
in class Shape
protected void clearSizeChangeListeners()
clearSizeChangeListeners
in class Shape
public boolean isInterpolateRequired()