public class Entity extends Object
| Type | Property and Description |
|---|---|
javafx.beans.property.ReadOnlyBooleanProperty |
active |
javafx.beans.property.DoubleProperty |
angle |
javafx.beans.property.ReadOnlyDoubleProperty |
height |
javafx.beans.property.ObjectProperty<Serializable> |
type |
javafx.beans.property.ReadOnlyDoubleProperty |
width |
javafx.beans.property.DoubleProperty |
x |
javafx.beans.property.DoubleProperty |
y |
| Constructor and Description |
|---|
Entity() |
| Modifier and Type | Method and Description |
|---|---|
javafx.beans.property.ReadOnlyBooleanProperty |
activeProperty() |
void |
addComponent(Component component)
Adds given component to this entity.
|
void |
addControl(Control control)
Adds behavior to entity.
|
void |
addModuleListener(ModuleListener listener) |
javafx.beans.property.DoubleProperty |
angleProperty() |
Entity |
copy()
Creates a new instance, which is a copy of this entity.
|
double |
distance(Entity other) |
double |
getBottomY() |
BoundingBoxComponent |
getBoundingBoxComponent() |
javafx.geometry.Point2D |
getCenter() |
<T extends Component> |
getComponent(Class<T> type)
Returns component of given type, or null if type not registered.
|
<T extends Component> |
getComponentOptional(Class<T> type)
Returns component of given type, or
Optional.empty()
if type not registered. |
Array<Component> |
getComponents()
Warning: object allocation.
|
<T extends Control> |
getControl(Class<T> type)
Returns control of given type or null if no such type is registered.
|
<T extends Control> |
getControlOptional(Class<T> type)
Returns control of given type or
Optional.empty() if
no such type is registered on this entity. |
Array<Control> |
getControls()
Warning: object allocation.
|
double |
getHeight() |
javafx.geometry.Point2D |
getPosition() |
PositionComponent |
getPositionComponent() |
ObjectMap<String,Object> |
getProperties() |
<T> T |
getProperty(String key) |
<T> Optional<T> |
getPropertyOptional(String key) |
RenderLayer |
getRenderLayer() |
double |
getRightX() |
double |
getRotation() |
RotationComponent |
getRotationComponent() |
Optional<JavaScriptParser> |
getScriptHandler(String scriptType) |
Serializable |
getType()
Gets the value of the property type.
|
TypeComponent |
getTypeComponent() |
EntityView |
getView() |
ViewComponent |
getViewComponent() |
double |
getWidth() |
GameWorld |
getWorld() |
double |
getX() |
double |
getY() |
boolean |
hasComponent(Class<? extends Component> type) |
boolean |
hasControl(Class<? extends Control> type) |
javafx.beans.property.ReadOnlyDoubleProperty |
heightProperty() |
boolean |
isActive()
Entity is "active" from the moment it is added to the world
and until it is removed from the world.
|
boolean |
isColliding(Entity other) |
boolean |
isType(Object type)
Example:
entity.isType(Type.PLAYER);
|
boolean |
isWithin(javafx.geometry.Rectangle2D bounds) |
void |
load(Bundle bundle)
Load entity state from a bundle.
|
boolean |
removeComponent(Class<? extends Component> type)
Remove a component with given type from this entity.
|
boolean |
removeControl(Class<? extends Control> type) |
void |
removeFromWorld()
Equivalent to world?.removeEntity(this);
|
void |
removeModuleListener(ModuleListener listener) |
void |
rotateBy(double angle)
Rotate entity view by given angle clockwise.
|
void |
rotateToVector(javafx.geometry.Point2D vector)
Set absolute rotation of the entity view to angle
between vector and positive X axis.
|
void |
save(Bundle bundle)
Save entity state into bundle.
|
void |
setControlsEnabled(boolean b)
Setting this to false will disable each control's update until this has
been set back to true.
|
void |
setOnActive(Runnable action)
Set a callback for when entity is added to world.
|
void |
setOnNotActive(Runnable action)
Set a callback for when entity is removed from world.
|
void |
setPosition(double x,
double y)
Set top left position of this entity in world coordinates.
|
void |
setPosition(javafx.geometry.Point2D position)
Set top left position of this entity in world coordinates.
|
void |
setProperty(String key,
Object value) |
void |
setRenderLayer(RenderLayer layer) |
void |
setRotation(double angle)
Set absolute rotation angle.
|
void |
setScaleX(double scaleX)
Scale view x.
|
void |
setScaleY(double scaleY)
Scale view y.
|
void |
setType(Serializable type)
Sets the value of the property type.
|
void |
setView(javafx.scene.Node view) |
void |
setViewFromTexture(String textureName)
Set view from texture.
|
void |
setViewFromTextureWithBBox(String textureName)
Set view from texture and generate bbox from it.
|
void |
setViewWithBBox(javafx.scene.Node view)
Set view and generate bounding boxes from view.
|
void |
setX(double x)
Set position top left x of this entity.
|
void |
setY(double y)
Set position top left y of this entity.
|
String |
toString() |
void |
translate(double dx,
double dy)
Translate x and y by given vector.
|
void |
translate(javafx.geometry.Point2D vector)
Translate x and y by given vector.
|
void |
translate(Vec2 vector)
Translate x and y by given vector.
|
void |
translateTowards(javafx.geometry.Point2D point,
double distance)
Instantly moves this entity distance units towards given point.
|
void |
translateX(double dx)
Translate x by given value.
|
void |
translateY(double dy)
Translate y by given value.
|
javafx.beans.property.ObjectProperty<Serializable> |
typeProperty() |
javafx.beans.property.ReadOnlyDoubleProperty |
widthProperty() |
javafx.beans.property.DoubleProperty |
xProperty() |
javafx.beans.property.DoubleProperty |
yProperty() |
public final javafx.beans.property.ObjectProperty<Serializable> typeProperty
getType(),
setType(Serializable)public final javafx.beans.property.DoubleProperty xProperty
getX(),
setX(double)public final javafx.beans.property.DoubleProperty yProperty
getY(),
setY(double)public final javafx.beans.property.DoubleProperty angleProperty
public final javafx.beans.property.ReadOnlyDoubleProperty widthProperty
getWidth()public final javafx.beans.property.ReadOnlyDoubleProperty heightProperty
getHeight()public final javafx.beans.property.ReadOnlyBooleanProperty activeProperty
isActive()public GameWorld getWorld()
public final void removeFromWorld()
public final TypeComponent getTypeComponent()
public final PositionComponent getPositionComponent()
public final RotationComponent getRotationComponent()
public final BoundingBoxComponent getBoundingBoxComponent()
public final ViewComponent getViewComponent()
public final Serializable getType()
public final void setType(Serializable type)
public final boolean isType(Object type)
Example:
entity.isType(Type.PLAYER);
type - entity typepublic final javafx.beans.property.ObjectProperty<Serializable> typeProperty()
getType(),
setType(Serializable)public final javafx.geometry.Point2D getPosition()
public final void setPosition(javafx.geometry.Point2D position)
public final void setPosition(double x,
double y)
public final double getX()
public final double getY()
public final void setX(double x)
public final void setY(double y)
public final javafx.beans.property.DoubleProperty xProperty()
getX(),
setX(double)public final javafx.beans.property.DoubleProperty yProperty()
getY(),
setY(double)public final void translate(javafx.geometry.Point2D vector)
public final void translate(Vec2 vector)
public final void translate(double dx,
double dy)
dx - vector xdy - vector ypublic final void translateX(double dx)
public final void translateY(double dy)
public final void translateTowards(javafx.geometry.Point2D point,
double distance)
point - the point to move towardsdistance - the distance to movepublic final double distance(Entity other)
public final double getRotation()
public final void setRotation(double angle)
public final javafx.beans.property.DoubleProperty angleProperty()
public final void rotateBy(double angle)
PhysicsComponent.angle - rotation angle in degreespublic final void rotateToVector(javafx.geometry.Point2D vector)
vector - the rotation vector / velocity vectorpublic final double getWidth()
public final double getHeight()
public final javafx.beans.property.ReadOnlyDoubleProperty widthProperty()
getWidth()public final javafx.beans.property.ReadOnlyDoubleProperty heightProperty()
getHeight()public final double getRightX()
public final double getBottomY()
public final javafx.geometry.Point2D getCenter()
public final boolean isColliding(Entity other)
other - the other game entitypublic final boolean isWithin(javafx.geometry.Rectangle2D bounds)
bounds - a rectangular box that represents boundspublic final EntityView getView()
public final void setView(javafx.scene.Node view)
public final void setViewFromTexture(String textureName)
textureName - name of texturepublic final void setViewFromTextureWithBBox(String textureName)
textureName - name of texturepublic final void setViewWithBBox(javafx.scene.Node view)
public final RenderLayer getRenderLayer()
public final void setRenderLayer(RenderLayer layer)
public final void setScaleX(double scaleX)
public final void setScaleY(double scaleY)
public final javafx.beans.property.ReadOnlyBooleanProperty activeProperty()
isActive()public final boolean isActive()
public final void setOnActive(Runnable action)
action - callbackpublic final void setOnNotActive(Runnable action)
action - callbackpublic final void setControlsEnabled(boolean b)
b - controls enabled flagpublic final void setProperty(String key, Object value)
key - property keyvalue - property valuepublic final <T> T getProperty(String key)
key - property keypublic final <T> Optional<T> getPropertyOptional(String key)
key - property keypublic final boolean hasControl(Class<? extends Control> type)
type - control typepublic final <T extends Control> Optional<T> getControlOptional(Class<T> type)
Optional.empty() if
no such type is registered on this entity.type - control typepublic final <T extends Control> T getControl(Class<T> type)
type - control typepublic final Array<Control> getControls()
public final void addControl(Control control)
control - the behaviorIllegalArgumentException - if control with same type already registered or anonymousIllegalStateException - if components required by the given control are missing or if within update of another controlpublic final boolean removeControl(Class<? extends Control> type)
type - the control type to removeIllegalStateException - if within update of another controlpublic final boolean hasComponent(Class<? extends Component> type)
type - component typepublic final <T extends Component> Optional<T> getComponentOptional(Class<T> type)
Optional.empty()
if type not registered.type - component typepublic final <T extends Component> T getComponent(Class<T> type)
type - component typepublic final Array<Component> getComponents()
public final void addComponent(Component component)
component - the componentIllegalArgumentException - if a component with same type already registered or anonymousIllegalStateException - if components required by the given component are missingpublic final boolean removeComponent(Class<? extends Component> type)
type - type of the component to removeIllegalArgumentException - if the component is required by other components / controlspublic void addModuleListener(ModuleListener listener)
public void removeModuleListener(ModuleListener listener)
public final Optional<JavaScriptParser> getScriptHandler(String scriptType)
public Entity copy()
public void save(Bundle bundle)
bundle - the bundle to write topublic void load(Bundle bundle)
bundle - bundle to read fromCopyright © 2017. All rights reserved.