Class World
A collection of Systems and Entities.
A world emits to let Systems iterate. A World contains any amount of Systems. A World contains any amount of Entities.
Methods
World:new () | Creates a new World. |
World:addEntity (e) | Adds an Entity to the World. |
World:newEntity () | Creates a new Entity and adds it to the World. |
World:removeEntity (e) | Removes an Entity from the World. |
World:addSystem (systemClass) | Adds a System to the World. |
World:addSystems (...) | Adds multiple Systems to the World. |
World:hasSystem (systemClass) | Returns if the World has a System. |
World:getSystem (systemClass) | Gets a System from the World. |
World:emit (functionName, ...) | Emits a callback in the World. |
World:clear () | Removes all entities from the World |
World:onEntityAdded (e) | Callback for when an Entity is added to the World. |
World:onEntityRemoved (e) | Callback for when an Entity is removed from the World. |
World:setResource (name, resource) | Sets a named resource in the world |
World:getResource (name) | Gets a named resource from the world |
Methods
- World:new ()
-
Creates a new World.
Returns:
-
World
The new World
- World:addEntity (e)
-
Adds an Entity to the World.
Parameters:
- e Entity Entity to add
Returns:
-
World
self
- World:newEntity ()
-
Creates a new Entity and adds it to the World.
Returns:
-
Entity
e the new Entity
- World:removeEntity (e)
-
Removes an Entity from the World.
Parameters:
- e Entity Entity to remove
Returns:
-
World
self
- World:addSystem (systemClass)
-
Adds a System to the World.
Callbacks are registered automatically
Entities added before are added to the System retroactively
Parameters:
- systemClass System SystemClass of System to add
Returns:
-
World
self
See also:
- World:addSystems (...)
-
Adds multiple Systems to the World.
Callbacks are registered automatically
Parameters:
- ... SystemClasses of Systems to add
Returns:
-
World
self
See also:
- World:hasSystem (systemClass)
-
Returns if the World has a System.
Parameters:
- systemClass System SystemClass of System to check for
Returns:
-
boolean
- World:getSystem (systemClass)
-
Gets a System from the World.
Parameters:
- systemClass System SystemClass of System to get
Returns:
-
System
System to get
- World:emit (functionName, ...)
-
Emits a callback in the World.
Calls all functions with the functionName of added Systems
Parameters:
- functionName string Name of functions to call.
- ... Parameters passed to System's functions
Returns:
-
World
self
- World:clear ()
-
Removes all entities from the World
Returns:
-
World
self
- World:onEntityAdded (e)
-
Callback for when an Entity is added to the World.
Parameters:
- e Entity The Entity that was added
- World:onEntityRemoved (e)
-
Callback for when an Entity is removed from the World.
Parameters:
- e Entity The Entity that was removed
- World:setResource (name, resource)
-
Sets a named resource in the world
Parameters:
- name string Name of the resource
- resource Any Resource to set
Returns:
-
World
self
- World:getResource (name)
-
Gets a named resource from the world
Parameters:
- name string Name of the resource
Returns:
-
Any
resource