Entity Types - ecbambrick/SimpleEntityComponentSystem GitHub Wiki
Entity types are groups of entities filtered by components. Each type contains a list of component names. When creating systems, you can query for entities based on their types. Any entity that contains all of these components is automatically added to that type. Attaching and detaching components, as well as deleting and creating entities, will automatically update each type.
For example, if you need to determine collisions, you can create an entity type containing all components related to collision (ie - position, hitbox). Within a collision system, you can request all entities of this type and simply iterate through them and apply logic.
Functions
nil secs.type(name
, componentName...
)
Creates a new type which requires each of the supplied component names.
entityList secs.query(component...
)
returns a list of entities that contain all of the components in the type.
Examples
-- create an entity type
secs.type("collidable", "position", "hitbox")
-- get the list of all entities that have a position and hitbox; iterate through them
collidableObjects = secs.query("collidable")
for entity in ipairs(collidableObjects) do
-- game logic
end