Basic Setup
Check out the Spinning Rectangles example to see the code below applied.
#
Creating a WorldThe 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.
World
#
Defining and Adding Systems to the In Ecstatic, A System
is a function. Associated Components
are defined when the System
is added to the World
via world.addSystem()
.
#
Creating EntitiesAn Entity
instance my be created in two ways:
- Calling
world.createEntity()
;
- Calling
new
on theEntity
Class 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 EntityIn 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 SystemsRun all Systems
added to the World
instance by calling world.systems.run()
. This will traditionally be called in render loop.
#
Querying EntitiesThere 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: