public interface Entity
An entity can consist of multiple components that define the behaviors and characteristics of the entity. In the entity hierarchy, an entity can have multiple child entities.
| 限定符和类型 | 字段 | 说明 |
|---|---|---|
static int |
INVALID_ENTITY |
Indicates the ID of an invalid entity.
|
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
<ComponentType extends Component> |
addComponent(Class<ComponentType> componentType) |
Adds a component of a specified type to an entity.
|
<ComponentType extends Component> |
getComponent(Class<ComponentType> componentType) |
Obtains the component of a specified type from the entity.
|
int |
getId() |
Obtains the unique ID of an entity in a scene.
|
boolean |
isValid() |
Checks whether an entity is valid.
|
<ComponentType extends Component> |
setComponent(ComponentType component) |
Sets the component data of an entity to the input component data.
|
static final int INVALID_ENTITY
int getId()
boolean isValid()
true if the entity is valid; returns false otherwise.<ComponentType extends Component> ComponentType addComponent(Class<ComponentType> componentType)
The new component is initialized with the default value.
ComponentType - Indicates the type of the component to add to the entity.componentType - Indicates the type of the component to add as a class object.IllegalArgumentException - Throws this exception if the component type is not found.<ComponentType extends Component> Optional<ComponentType> getComponent(Class<ComponentType> componentType)
ComponentType - Indicates the type of the component to obtain from the entity.componentType - Indicates the type of the component to obtain as a class object.IllegalArgumentException - Throws this exception if the component type is not found.<ComponentType extends Component> void setComponent(ComponentType component)
ComponentType - Indicates the component type.component - Indicates the component data to set.IllegalArgumentException - Throws this exception if the component of the specified type is not found.