Basic Setup
Check out the Spinning Rectangles example to see the code below applied.
Creating a World#
The first thing that must be done is creating an instance of a World. A World in Ecstatic contains all instances of entities, and also facilitates registering of systems. The World's API methods will be used used to do things like add Systems, create Entities, query Components, and more.
Defining and Adding Systems to the World#
In Ecstatic, A System is a function. Associated Components are defined when the System is added to the World via world.addSystem().
Creating Entities#
An Entity instance my be created in two ways:
- Calling
world.createEntity();
- Calling
newon theEntityClass Constructor;
info
Currently, lifecycle methods may only be added to Entities when they are defined via the new Entity().
Creating Component Instances and adding them to an Entity#
In Ecstatic, any Class Instance (including functions, see info below) are valid Components, and should be able to be added as such on to an Entity.
info
Note: Since this is Javascript, and "Everything is an Object, even Functions", there is experimental support for using Functions as Components. The use case for exactly why this is helpful is still to be determined. If you would like to experiment with this, then tread carefully, and let us know your results and suggestions.
Running Systems#
Run all Systems added to the World instance by calling world.systems.run(). This will traditionally be called in render loop.
Querying Entities#
There are many methods available on the World instance to query entites by what types of Components are attached to them. There is no need to define a "Query" ahead of time. For a complete list, check out the World Instance Methods in the API Documentation. Some highlights include: