-
Notifications
You must be signed in to change notification settings - Fork 113
System
Artemis-odb provides many types of systems. You will use IteratingSystem
and BaseSystem
the most.
Iterating systems operate over entities that match a certain Aspect.
// What do we subscribe to?
@One(Cookie.class, Bread.class)
@Exclude(Baked.class)
public class BakingSystem extends IteratingSystem {
// odb injects dependencies automatically.
ComponentMapper<Baked> mBaked; // used to access component.
/* called for each matching entity. */
@Override
protected void process(int e) {
mBaked.create(e); // bake cookie! (adds Bake component if missing)
}
}
See World how to add this system to your game.
To subscribe your system to entities of a certain composition, use aspect annotations.
// Anotations can be combined.
@All(A.class,B.class,C.class) // The entity must have `A` and 'B' and 'C' component.
@One(D.class, E.class) // The entity must possess at least one of `D` OR `E` component.
@Exclude(F.class, G.class) // The entity may not possess `F` or 'G' component.
public class MySystem extends IteratingSystem {
..
Artemis-odb handles most object creation for you. It will inject systems, Component mappers, or any other desired any object into entity systems, during initialization:
public class MySystem extends ... {
private ComponentMapper<Position> mPosition;
private MyOtherSystem myOtherSystem;
private MyObject object;
private
}
By default, systems inject inherited fields from superclasses. Override this behavior with @Wire(injectInherited=true)
.
By default, if @Wire fails to inject a field - typically because the requested type hasn't been added to the world instance - a MundaneWireException
is thrown. Override this behavior via @Wire(failOnNull=false)
.
When injectables are required outside systems, the world can inject any object:
world.inject(this)
- Injecting non-artemis dependencies
- GWT reflection common issues and solutions
- Roll your own injection logic with Customized-injection
- Overview
- Concepts
- Getting Started
- Using
- More guides
- Plugins
- Game Gallery
- Tools and Frameworks
- API reference