class Scar::Entity
- Scar::Entity
- SF::Transformable
- Reference
- Object
Overview
An entity is any independent thing in your application, like a button, the player, an enemy, ...
An entity contains Component
s. They define the entity; An entity itself only has an id and transformational data (position, rotation, scale, z).
Being a subclass of SF::Transformable
, its transform
is applied if this entity or any of its components is drawn.
Example usage:
player_sprite = Scar::Components::Sprite.new Assets.texture("textures/player.png")
player = Scar::Entity.new("player", PlayerComponent.new, player_sprite, Scar::Vec.new(100, 100), z: 1)
Direct Known Subclasses
Defined in:
scar/entity.crConstructors
- .new(id : String, components : Array(Component), *, position : Vec | Nil = nil, scale : Vec | Nil = nil, rotation : Float32 | Nil = nil, z : Int32 = 0)
- .new(id : String, *comps : Component, position : Vec | Nil = nil, scale : Vec | Nil = nil, rotation : Float32 | Nil = nil, z : Int32 = 0)
- .new(id : String, *, position : Vec | Nil = nil, scale : Vec | Nil = nil, rotation : Float32 | Nil = nil, z : Int32 = 0)
Instance Method Summary
-
#<<(c : Component)
Adds a component to this entity and returns self
-
#<<(*cs : Component)
Adds multiple components to this entity and returns self
-
#[](comp_type : T.class) : T forall T
Returns this entities' component of given type
-
#[]?(comp_type : T.class) : T | Nil forall T
Returns this entities' component of given type or nil if it was not found
-
#alive? : Bool
Getter for alive
- #components : Array(Scar::Component)
- #components=(components : Array(Scar::Component))
-
#destroy
Marks this entity for removal
-
#has?(c : Component.class) : Bool
Checks if this entity contains a component of the given type
-
#has?(cs : Array(Component.class)) : Bool
Checks if this entity contains a component of every given type
-
#has?(*cs : Component.class) : Bool
Checks if this entity contains a component of every given type
- #id : String
-
#z : Int32
Used to specify the rendering order
-
#z=(z : Int32)
Used to specify the rendering order
Constructor Detail
Instance Method Detail
Returns this entities' component of given type
Returns this entities' component of given type or nil if it was not found
Checks if this entity contains a component of the given type
Checks if this entity contains a component of every given type
Checks if this entity contains a component of every given type