dominion-dev / dominion-ecs-java

Insanely fast ECS (Entity Component System) for Java
https://dominion-dev.github.io
MIT License
288 stars 18 forks source link

how to get component from entity #116

Closed endison1986 closed 1 year ago

endison1986 commented 1 year ago

how to get component from entity?

Dominion dominion= Dominion.create();
dominion.createEntity(comp1, comp2);
/// ....

final var scheduler = dominion.createSchduler();
scheduler.schedule(()->{
  dominion.findEntitiesWith(Component1.class, Component2.class).stream().forEach(rs->{
    final var entity = rs.entity();
    ///...
    if(entity.has(Component3.class)) {
        final var comp3 = entity.get(Component3.class);
    } else {
        fianl var comp3 = new Component3();
        ///... to config comp3
        entity.add(comp3);
    }
  });
});

scheduler.tickAtFixedRate(3);
enricostara commented 1 year ago

With a new findEntitiesWith (including Component3) that could be even in another system with a different/specific responsibility.

endison1986 commented 1 year ago

thank you, I will try it.