Artemis - Multiple instance of EntityManager

时间:2018-04-18 18:07:23

标签: artemis

I'm using the Artemis-odb framework for coding game in Java (https://github.com/junkdog/artemis-odb).

I would like to instantiate some Entity (for example, buildings and people/workers). I've also seen the EntityManager class of the framework and tried to use it.

Here is my problem :

  • I don't want to have a huge class extending EntityManager and having all the "create" methods because it will be an awful class --> too much lines of code, no lisibility, no thanks.
  • I tried to create mutliple classes extending EntityManager, but then, each has its "nextId" value (it enables to know the id to give to the new Entity) --> I obtain mutliple entities with the same id.
  • If I create multiple classes and reference only one EntityManager, I can't access to the create method of the EntityManager because this method is protected.
  • An other solution I tried was to create different classes with only static methods and referencing an EntityManager. But my EntityManagers need to have non-static methods due to another reason (I spare the details).

Do you have any viable solution? There is not so much documentation for now about this framework so it's a bit complicated!

Thanks,

1 个答案:

答案 0 :(得分:0)

我回答我的问题,以防它对某人有用。

最后,我没有使用框架的类EntityManager。 我为我需要的东西(建筑物,工人等)创建了几个EntityManagers,并使它们从BaseSystem继承。 有了它,我可以通过这个世界访问它们并做我想做的事。