Skip to content
MarcosAlfonso edited this page Oct 10, 2014 · 17 revisions

Ember: A component based entity framework for Flash and Flex with DI

Ember was created to combine the best of component/entity based game architecture and DI driven frameworks.

Design Principles

Ember is built on some core design principles that may help to understand the architectural design choices.

  1. Composition and interfaces are favoured over inheritance
  2. Modular (Multiple ember games can simultaneously co-exist, No singletons)
  3. Minimalist (It’s a framework not a game engine)
  4. Data driven

So what is component/entity based architecture?

There are many interpretations of how to implement this kind of architecture, Ember closely follows the concepts descibed in this blog
http://t-machine.org/index.php/2007/09/03/entity-systems-are-the-future-of-mmog-development-part-1/
Note: this is not traditional OOP it breaks the rules but with good reason.

There are 3 main parts Entities, Components and Systems.

Entities

Entities are just a unique key for retrieving components although they have some methods for convenience they are essentially just a key. In Ember you create an entity like this.

var e:IEntity = entityManager.createEntity("bob");

Components

Components are just data they have no methods. Components can be registered with an entity. Together with entities these make up the games data model. You can add a component to an entity like this

e.addComponent(new Spacial2D());

and you can retrieve a compoment from an entity like this

var spacial:Spacial2D = e.getComponent(Spacial2D());

Systems

Systems are where all the work is done. Systems can communicate with other systems via events. Systems can also request a list of entities with a specific set of components and act on them. Systems use automated DI to make coding them quick and clean. For example all games would probably have a render system. You can register a system with the game like this.

systemManager.addSystem(ProcessManager);

and a system can retrieve a list of entities with a set of components like this

var renderableEntities:Vector.<IEntity> = entityManager.getEntityFamily(Graphics,Spacial2D);

read more in getting started