Skip to content
TristanPearce edited this page Jul 8, 2017 · 4 revisions

I am assuming you already know what Ashley is, and how to work with it, if not, head to their wiki first and come back here when you do.

In short. Ashley will provide you with engine that you need to update on each of your render calls. Engine consists of many entities, that are empty containers that hold no data. Each entity in overlap2D will represent an item on the scene, like image or so. Each entity contains Components that describe it. And then Engine contains Systems that work with entities on each iteration based on their components.

The rendering itself is done by one of the systems that is responsible for rendering. It is iterating over the root-most entity on the nested structure, and goes deep in.

Now of course this entire big structure of entities, components and systems is created by Overlap2D. First when you create SceneLoader it prepares en empty engine, and adds all the default Overlap2D systems to it. They do nothing as there is no entities to iterate over. When loadScene is called. SceneLoader is asking EntityFactory to create the root most element based on it's VO data from JSON. The root entity contains Viewport component which is the camera for rendering. It then goes on recursively deep to create all the other entities.

Default Item Components

While creating Entities, ComponentFactory kicks in, and creates all components based on the item types. Here is the list of components that Overlap2D puts on them.

  • MainItemComponent - this one is present on every item, and contains core data, such as item unique id's, custom variables, tags, item type and library links.
  • TransformComponent, DimensionComponent, TintComponent, ZIndexComponent - these are components that again almost all items have, they contain data such as coordinates, scales, origin points, overall boundaries and sizes, color tints, layer ownership, and z-index render ordering.
  • TextureRegionComponent, SpriteAnimationComponent, LabelComponent - and others are present depending on item type,
  • NodeComponent - is present only on Composite items (Groups), that contain other items inside, this component will contain list of child entities by reference.
  • ViewportComponent - is present only on root entity, and has camera data in it. Only one entity can have this component at a time, and it will be the one that rendering starts from. for example if it is an image or other somthing that has a texture region, it will have TextureRegionComponent on it. There are other components too that are based on situation, some for inner runtime use, some for physics, some for lights and so on.

When user needs to do dynamic changes to the scene, then SceneLoader will provide back things like Engine itself, where it's possible to add/remove entities. But the core of operations is located in EntityFactory and ComponentFactory.

Because this is a self contained framework, and rendering happens via one of the systems. then all user has to do on each frame is call engine.update() method. And it will take care of the rest, including all logic and rendering.