public class Engine
extends java.lang.Object
Entity
and
managing EntitySystem
objects. The Engine should be updated every tick via the update(float)
method.
With the Engine you can:
Entity
objectsEntitySystem
sFamily
EntityListener
objectsConstructor and Description |
---|
Engine() |
Modifier and Type | Method and Description |
---|---|
void |
addEntity(Entity entity)
Adds an entity to this Engine.
|
protected void |
addEntityInternal(Entity entity) |
void |
addEntityListener(EntityListener listener)
Adds an
EntityListener . |
void |
addEntityListener(Family family,
EntityListener listener)
Adds an
EntityListener for a specific Family . |
void |
addEntityListener(Family family,
int priority,
EntityListener listener)
Adds an
EntityListener for a specific Family . |
void |
addEntityListener(int priority,
EntityListener listener)
Adds an
EntityListener . |
void |
addSystem(EntitySystem system)
Adds the
EntitySystem to this Engine. |
<T extends Component> |
createComponent(java.lang.Class<T> componentType)
Creates a new
Component . |
Entity |
createEntity()
Creates a new Entity object.
|
ImmutableArray<Entity> |
getEntities()
Returns an
ImmutableArray of Entity that is managed by the the Engine
but cannot be used to modify the state of the Engine. |
ImmutableArray<Entity> |
getEntitiesFor(Family family)
Returns immutable collection of entities for the specified
Family . |
<T extends EntitySystem> |
getSystem(java.lang.Class<T> systemType)
Quick
EntitySystem retrieval. |
ImmutableArray<EntitySystem> |
getSystems() |
void |
removeAllEntities()
Removes all entities registered with this Engine.
|
void |
removeAllEntities(Family family)
Removes all entities of the given
Family . |
void |
removeAllSystems()
Removes all systems from this Engine.
|
void |
removeEntity(Entity entity)
Removes an entity from this Engine.
|
protected void |
removeEntityInternal(Entity entity) |
void |
removeEntityListener(EntityListener listener)
Removes an
EntityListener |
void |
removeSystem(EntitySystem system)
Removes the
EntitySystem from this Engine. |
void |
update(float deltaTime)
Updates all the systems in this Engine.
|
public <T extends Component> T createComponent(java.lang.Class<T> componentType)
Component
. To use that method your components must have a visible no-arg constructorpublic void addEntity(Entity entity)
public void removeEntity(Entity entity)
public void removeAllEntities(Family family)
Family
.public void removeAllEntities()
public ImmutableArray<Entity> getEntities()
ImmutableArray
of Entity
that is managed by the the Engine
but cannot be used to modify the state of the Engine. This Array is not Immutable in
the sense that its contents will not be modified, but in the sense that it only reflects
the state of the engine.
The Array is Immutable in the sense that you cannot modify its contents through the API of
the ImmutableArray
class, but is instead "Managed" by the Engine itself. The engine
may add or remove items from the array and this will be reflected in the returned array.
This is an important note if you are looping through the returned entities and calling operations
that may add/remove entities from the engine, as the underlying iterator of the returned array
will reflect these modifications.
The returned array will have entities removed from it if they are removed from the engine,
but there is no way to introduce new Entities through the array's interface, or remove
entities from the engine through the array interface.
Discussion of this can be found at https://github.com/libgdx/ashley/issues/224public void addSystem(EntitySystem system)
EntitySystem
to this Engine.
If the Engine already had a system of the same class,
the new one will replace the old one.public void removeSystem(EntitySystem system)
EntitySystem
from this Engine.public void removeAllSystems()
public <T extends EntitySystem> T getSystem(java.lang.Class<T> systemType)
EntitySystem
retrieval.public ImmutableArray<EntitySystem> getSystems()
Engine
.public ImmutableArray<Entity> getEntitiesFor(Family family)
Family
.
Returns the same instance every time for the same Family.public void addEntityListener(EntityListener listener)
EntityListener
.
The listener will be notified every time an entity is added/removed to/from the engine.public void addEntityListener(int priority, EntityListener listener)
EntityListener
. The listener will be notified every time an entity is added/removed
to/from the engine. The priority determines in which order the entity listeners will be called. Lower
value means it will get executed first.public void addEntityListener(Family family, EntityListener listener)
EntityListener
for a specific Family
.
The listener will be notified every time an entity is added/removed to/from the given family.public void addEntityListener(Family family, int priority, EntityListener listener)
EntityListener
for a specific Family
. The listener will be notified every time an entity is
added/removed to/from the given family. The priority determines in which order the entity listeners will be called. Lower
value means it will get executed first.public void removeEntityListener(EntityListener listener)
EntityListener
public void update(float deltaTime)
deltaTime
- The time passed since the last frame.protected void addEntityInternal(Entity entity)
protected void removeEntityInternal(Entity entity)