Package dev.prozilla.pine.core.entity
Class Entity
- All Implemented Interfaces:
Lifecycle
,Printable
,ComponentFinder
,EntityFinder
public class Entity
extends EventDispatcher<EntityEvent>
implements Lifecycle, Printable, EntityFinder, ComponentFinder
Represents a unique entity in the world with a list of components.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates an entity at the position (0, 0)Creates an entity at the position (x, y)Creates an entity at the position (0, 0)Creates an entity at the position (x, y) -
Method Summary
Modifier and TypeMethodDescriptionAdds a child to this entity.Instantiates a prefab and adds the instance as a child of this entityvoid
addChildren
(Entity... children) Adds children to this entity.<C extends Component>
CaddComponent
(C component) Adds a component to this entity.void
destroy()
Destroys this entity at the end of the game loop.boolean
Checks whether two entities are equal.getChildWithTag
(String tag) <ComponentType extends Component>
ComponentTypegetComponent
(Class<ComponentType> componentClass) Returns a component of a given class or null of there isn't one.<ComponentType extends Component>
ComponentTypegetComponentInParent
(Class<ComponentType> componentClass) <ComponentType extends Component>
ComponentTypegetComponentInParent
(Class<ComponentType> componentClass, boolean includeAncestors) getComponents
(Class<ComponentType> componentClass) Returns all components of a given class.getComponentsInChildren
(Class<ComponentType> componentClass) getInput()
getName()
getParentWithTag
(String tag) getScene()
getTimer()
getWorld()
<ComponentType extends Component>
booleanhasComponent
(Class<ComponentType> componentClass) Checks if this entity has a component of a given class.int
hashCode()
boolean
boolean
isActive()
boolean
void
void
removeChild
(Entity child) Detaches a child from this entity without removing it from the world.void
removeChildren
(Entity... children) Detaches children from this entity without removing them from the world.void
removeComponent
(Component component) Removes a component from this entity.void
setActive
(boolean active) Enables/disables this entity.void
Setter for the parent entity.toString()
Returns a string representation of this object.Methods inherited from class dev.prozilla.pine.common.event.EventDispatcher
addListener, invoke, removeListener, setLogger
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Field Details
-
id
public final int id -
tag
-
isActive
protected boolean isActive -
transform
-
world
-
application
-
logger
-
scene
-
components
Components of this entity
-
-
Constructor Details
-
Entity
Creates an entity at the position (0, 0) -
Entity
Creates an entity at the position (0, 0) -
Entity
Creates an entity at the position (x, y) -
Entity
Creates an entity at the position (x, y)
-
-
Method Details
-
destroy
public void destroy()Destroys this entity at the end of the game loop.- Specified by:
destroy
in interfaceLifecycle
- Overrides:
destroy
in classEventDispatcher<EntityEvent>
-
addChild
Instantiates a prefab and adds the instance as a child of this entity- Parameters:
prefab
- Prefab for the child entity- Returns:
- Child entity
- Throws:
IllegalStateException
IllegalArgumentException
-
addChild
Adds a child to this entity. Also adds the child to the world if this entity is inside the world.- Parameters:
child
- Entity to add as a child- Returns:
- Child entity
- Throws:
IllegalStateException
IllegalArgumentException
-
addChildren
Adds children to this entity.- Parameters:
children
- Child objects- Throws:
IllegalStateException
IllegalArgumentException
-
removeChild
Detaches a child from this entity without removing it from the world.- Parameters:
child
- Child object- Throws:
IllegalStateException
IllegalArgumentException
-
removeChildren
public void removeChildren(Entity... children) throws IllegalStateException, IllegalArgumentException Detaches children from this entity without removing them from the world.- Parameters:
children
- Child entities- Throws:
IllegalStateException
IllegalArgumentException
-
getChildWithTag
- Specified by:
getChildWithTag
in interfaceEntityFinder
-
getParentWithTag
- Specified by:
getParentWithTag
in interfaceEntityFinder
-
setParent
Setter for the parent entity.- Parameters:
parent
- Parent entity
-
setActive
public void setActive(boolean active) Enables/disables this entity. -
isActive
public boolean isActive() -
addComponent
Adds a component to this entity.- Parameters:
component
- Component
-
removeComponent
Removes a component from this entity.- Parameters:
component
- Component
-
getComponentInParent
public <ComponentType extends Component> ComponentType getComponentInParent(Class<ComponentType> componentClass) - Specified by:
getComponentInParent
in interfaceComponentFinder
-
getComponentInParent
public <ComponentType extends Component> ComponentType getComponentInParent(Class<ComponentType> componentClass, boolean includeAncestors) - Specified by:
getComponentInParent
in interfaceComponentFinder
-
getComponentsInChildren
public <ComponentType extends Component> List<ComponentType> getComponentsInChildren(Class<ComponentType> componentClass) - Specified by:
getComponentsInChildren
in interfaceComponentFinder
-
hasComponent
Checks if this entity has a component of a given class.- Parameters:
componentClass
- Class of the component.- Returns:
- True if this entity has a component of type
componentClass
.
-
getComponent
public <ComponentType extends Component> ComponentType getComponent(Class<ComponentType> componentClass) Returns a component of a given class or null of there isn't one.- Specified by:
getComponent
in interfaceComponentFinder
- Parameters:
componentClass
- Class of the component.- Returns:
- An instance of
componentClass
that is attached to this entity.
-
getComponents
public <ComponentType extends Component> List<ComponentType> getComponents(Class<ComponentType> componentClass) Returns all components of a given class.- Specified by:
getComponents
in interfaceComponentFinder
- Parameters:
componentClass
- Class of the components.- Returns:
- An ArrayList of instance of
componentClass
that are attached to this entity.
-
getName
-
getName
-
hasTag
-
getInput
-
getWindow
-
getRenderer
-
getTimer
-
getTracker
-
getApplication
-
getWorld
-
getScene
-
getCamera
-
getLogger
-
isRegistered
public boolean isRegistered() -
hashCode
public int hashCode() -
equals
Checks whether two entities are equal.- Parameters:
entity
- Other entity- Returns:
- True if the entities are equal
-
printHierarchy
public void printHierarchy() -
toString
Description copied from interface:Printable
Returns a string representation of this object.
-