Entity component system is able to solve problems of scale which can come during OO programming in game development. I have few queries regarding ECS:

To give an overview: There are entities which include some components (having data) and systems which have logic like walk logic, combat logic etc. So in any game, enemy is an entity, hero is an entity etc which has its own systems. Each player/enemy becomes an entity.

  1. Initially i was using stage, groups and actors, where stage was passing event to actor using the hierarchy and based on event i was handling that. Now as i have entity, What becomes my new actor? Is every entity will be an actor? If yes, then in each act, i will call all components update function and draw in draw function, right?
  2. Entity component system is used only for actor or should i use it for stage, groups, camera also? If should use for all, can someone help understand how?

In OO, it is simple as i add actors in group and stage transmit events to actors, based on event i do appropriate task. Sorry if i am missing something, as thinking in ECS is new to me. I started writing code, but then i got confused while thinking about whole system. I got it how to work for an actor, but how to make it work with group, stage, camera etc.

有帮助吗?

解决方案

Actually this question cannot be answered, because the Stage actually is some kind of entity system itself. The Stage can be interpreted as your entity system. A Group would be all entities with a certain component and Actors are your entities. Using Stage and a custom entity system together makes not much sense.

Certain technical/unique things like the Camera should not be modeled as entities at all. It's not necessary to press everything into the entity system and will not really fit in the end.

In total you should rethink why you actually need an entity component system. The main idea behind this programming style is to optimize the memory layout, by grouping all components together in memory. Using Java this will be pretty difficult anyway, because you cannot control where your objects will be that precisely (like you can in C++). Another motivation is to have abstract re-usable components that you can use for your entities, but you can actually also do that with standard OO entity hierarchy. For small games for mobile devices you will probably not have enough entities anyway, to really feel a noticable difference in performance and in my opinion the entity component system style does not fit everywhere.

If you still want to stick to it, do not use a Stage.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top