public abstract class EntitySystem extends GameSystem
Specialized GameSystem that handles a set of
Entities matching some constraints
At some point before being added to a GameEngine (usually in the
constructor), a subclass of this class should call one or more of
requireAll(Class[]),
requireOne(Class[]), or
forbid(Class[]) to describe which Entities should be
given to its onHandleEntity(Entity, float) method.
After the system is added, onHandleEntity(Entity, float) will
be called each game loop for every Entity that matches the given
constraints.
| Constructor and Description |
|---|
EntitySystem() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
forbid(java.lang.Class<?>... componentTypes)
Supply a list of components that must not be present in entities that will
be handled by this system
|
protected abstract void |
onHandleEntity(Entity entity,
float deltaTime)
Override to do something with the entities that match this system's
filter parameters
|
void |
onUpdate(GameEngine engine,
float deltaTime)
Called when this system should execute its main game loop behavior.
|
protected void |
requireAll(java.lang.Class<?>... componentTypes)
Supply a list of components that must all be present in entities that
will be handled by this system
|
protected void |
requireOne(java.lang.Class<?>... componentTypes)
Supply a list of components from which at least one must be present in
entities that will be handled by this system
|
public void onUpdate(GameEngine engine, float deltaTime)
GameSystemCalled when this system should execute its main game loop behavior.
This is where the system will do most of its work, and is called once for
each time GameEngine.update(float) is called on the attached
GameEngine.
onUpdate in class GameSystemengine - The engine this update is occurring indeltaTime - The time given to GameEngine.update(float) for
this iteration of the game loop; ostensibly, the time
between the previous loop and the current oneprotected void requireAll(java.lang.Class<?>... componentTypes)
Supply a list of components that must all be present in entities that will be handled by this system
A good place to call this is in a constructor
componentTypes - The components to includeprotected void requireOne(java.lang.Class<?>... componentTypes)
Supply a list of components from which at least one must be present in entities that will be handled by this system
May only be called before the system is added to a GameEngine,
and may not be called more than once
A good place to call this is in a constructor
componentTypes - The components to includejava.lang.IllegalStateException - If requireOne() has been called before, or if this system is already added to an engineprotected void forbid(java.lang.Class<?>... componentTypes)
Supply a list of components that must not be present in entities that will be handled by this system
May only be called before the system is added to a GameEngine,
and may not be called more than once
A good place to call this is in a constructor
componentTypes - The components to excludejava.lang.IllegalStateException - If forbid() has been called before, or if this system is already added to an engineprotected abstract void onHandleEntity(Entity entity, float deltaTime)
Override to do something with the entities that match this system's filter parameters
entity - A matching EntitydeltaTime - The time given to GameEngine.update(float) for
this iteration of the game loop; ostensibly, the time
between the previous loop and the current one