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 Entity
s and System
s.
Spaces live inside Scene
s.
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 << sp
Defined 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
Entity
with given id -
#[]?(id : String) : Entity | Nil
Returns the
Entity
with given id or returnnil
of no entity is found -
#camera : Scar::Objects::Camera
The default
Camera
object -
#camera=(camera : Scar::Objects::Camera)
The default
Camera
object -
#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)
end
The 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