crystal.ECS
Entry-point to the crystal.ecs module. Instances of this class manage a living set of entities and their components, as well as systems and queries to update them.
Constructor
crystal.ECS:new()
Methods
| Name | Description |
|---|---|
| add_context | Makes a value available to all entities created by this ECS. |
| add_system | Instantiates a new System. |
| context | Retrieves a value added via add_context. |
| components | Returns all components of a specific class or inheriting from it. |
| despawn | Unregisters an Entity from this ECS. |
| entities_with | Returns all entities that have a Component of a specific class or inheriting from it. |
| events | Returns a list of events of a specific class or inheriting from it. |
| notify_systems | Calls a method by name on all systems that support it. |
| spawn | Instantiates a new Entity. |
| system | Returns an existing System of a specific class or inheriting from it. |
| update | Clears events and updates all queries. |
Examples
local MyScene = Class("MyScene", crystal.Scene);
MyScene.init = function()
self.ecs = crystal.ECS:new();
end
MyScene.update = function(self, dt)
self.ecs:update();
self.ecs:notify_systems("input");
self.ecs:notify_systems("physics");
self.ecs:notify_systems("draw");
end