class Scar::Space
- Scar::Space
- Reference
- Object
Overview
A Space is a container for one independent layer of your application, like UI, Game World, Background, ...
A space contains Entitys and Systems.
Spaces live inside Scenes.
Spaces should not interact with each other.
Each Space has a default camera object, accessible through space#camera.
The camera object has the entity id __camera.
Example usage:
# Create a space with the id "ui", a system and two entities
sp = Scar::Space.new("ui", UpdateUISystem, health_bar, exit_button, 1)
scene << spDefined in:
scar/space.crConstructors
- .new(id : String, z : Int32 = 0)
- .new(id : String, *entities_or_systems : Entity | System, z : Int32 = 0)
Instance Method Summary
- 
        #<<(entity : Entity)
        
          Adds an Entity to the space and returns self 
- 
        #<<(sys : System)
        
          Adds a System to the space and returns self 
- 
        #<<(*entities_or_systems : Entity | System)
        
          Adds multiple Entities or Systems to the space and returns self 
- 
        #[](id : String) : Entity
        
          Returns the Entitywith given id
- 
        #[]?(id : String) : Entity | Nil
        
          Returns the Entitywith given id or returnnilof no entity is found
- 
        #camera : Scar::Objects::Camera
        
          The default Cameraobject
- 
        #camera=(camera : Scar::Objects::Camera)
        
          The default Cameraobject
- 
        #each_with(comp_type : T.class, &block : Entity, T -> ) forall T
        
          For each Entity having the given component in the space, yield the entity and it's component 
- 
        #each_with(comp_type : T.class, *other_comp_types : Component.class, &block : Entity, T -> ) forall T
        
          For each Entity having the given components in the space, yield the entity and it's comp_type component 
- #id : String
- #id=(id : String)
- 
        #z : Int32
        
          The z-coordinate of this space, used to specify the rendering order of multiple spaces 
- 
        #z=(z : Int32)
        
          The z-coordinate of this space, used to specify the rendering order of multiple spaces 
Constructor Detail
Instance Method Detail
Adds multiple Entities or Systems to the space and returns self
Returns the Entity with given id or return nil of no entity is found
For each Entity having the given component in the space, yield the entity and it's component
For each Entity having the given components in the space, yield the entity and it's comp_type component
Example usage:
# Subtract hp from every enemy entity in the player's range
space.each_with(EnemyComponent, Scar::Components::Sprite) do |ent, comp|
  comp.hp -= 10 if player.in_range?(ent)
endThe z-coordinate of this space, used to specify the rendering order of multiple spaces
The z-coordinate of this space, used to specify the rendering order of multiple spaces