Hi,
I want to retrieve all entities that contain component A and at least one of the components B and C.
It’s clear to me that I need an OrFilter to achieve this, but looking at the OrFilter constructors (or the factory methods) I don’t understand how to create one.
The OrFilter takes a class X (“type”) and a list of ComponentFilters Y (“operands”).
If an entity has a component X, it is immediately included in the result. Else each ComponentFilter in Y is checked (if Y is not null).
I tried using it like this:
ComponentFilter filter = OrFilter.create(ComponentB.class, OrFilter.create(ComponentC.class, null));
entitySet = entityData.getEntities(filter, ComponentA.class);
This does not work, because the OrFilter.create(…) method is defined as follows:
public static <T extends EntityComponent> OrFilter<T> create(Class<T> type, ComponentFilter<? extends T>[] operands) {
...
}
This means that all “type” classes in the “operands” filters must extends the initial “type” class.
Since entity components and inheritance don’t mix, I must be horribly misunderstanding something here. Can anybody please give me a brief example on how to use OrFilters?