public class Entity extends Object
| Type | Property and Description |
|---|---|
javafx.beans.property.ReadOnlyBooleanProperty |
active |
| 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) |
Entity |
copy()
Creates a new instance, which is a copy of this entity.
|
<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.
|
<T> T |
getProperty(String key) |
GameWorld |
getWorld() |
boolean |
hasComponent(Class<? extends Component> type) |
boolean |
hasControl(Class<? extends Control> type) |
boolean |
isActive()
Entity is "active" from the moment it is added to the world
and until it is removed from the world.
|
void |
load(Bundle bundle)
Load entity state from a bundle.
|
void |
removeAllComponents() |
void |
removeAllControls() |
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 |
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 |
setProperty(String key,
Object value) |
String |
toString() |
public final javafx.beans.property.ReadOnlyBooleanProperty activeProperty
isActive()public GameWorld getWorld()
public final void removeFromWorld()
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 keyIllegalArgumentException - if key doesn't existpublic 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 missingpublic final boolean removeControl(Class<? extends Control> type)
type - the control type to removepublic final void removeAllControls()
public 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 final void removeAllComponents()
public void addModuleListener(ModuleListener listener)
public void removeModuleListener(ModuleListener listener)
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.