Spaces
Last updated
Was this helpful?
Last updated
Was this helpful?
A space is a logical container for , and . It holds all things for one 'layer' of a . For example, there would be a space for the background, one for the level and one for the UI. Spaces should not interact with other spaces.
, and can be inserted via the <<
instance method but not removed. To remove entities, one has to call their Entity#suicide
method, all dead entities are removed upon the next update. Systems should not be removed.
Spaces have multiple ways to select . The []
and []?
methods can be used for direct access via entity id. Then there is each_with
. It is used to get all entities in a space which hold the specified . The call signatures are:
Both methods accept a block and yields the found and the with the type specified in the first parameter.
comp_type
and *comp_types
are classes (not instances) which inherit from Scar::Component
. comp_types
are not yielded but filtered for. This allows to only process entities with certain components. That way, empty components can also be used as tags.
To see the each_with
methods in action, please refer to the section.