class Scar::Entity

Overview

An entity is any independent thing in your application, like a button, the player, an enemy, ...

An entity contains Components. 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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(id : String, components : Array(Component), *, position : Vec | Nil = nil, scale : Vec | Nil = nil, rotation : Float32 | Nil = nil, z : Int32 = 0) #

[View source]
def self.new(id : String, *comps : Component, position : Vec | Nil = nil, scale : Vec | Nil = nil, rotation : Float32 | Nil = nil, z : Int32 = 0) #

[View source]
def self.new(id : String, *, position : Vec | Nil = nil, scale : Vec | Nil = nil, rotation : Float32 | Nil = nil, z : Int32 = 0) #

[View source]

Instance Method Detail

def <<(c : Component) #

Adds a component to this entity and returns self


[View source]
def <<(*cs : Component) #

Adds multiple components to this entity and returns self


[View source]
def [](comp_type : T.class) : T forall T #

Returns this entities' component of given type


[View source]
def []?(comp_type : T.class) : T | Nil forall T #

Returns this entities' component of given type or nil if it was not found


[View source]
def alive? : Bool #

Getter for alive


[View source]
def components : Array(Scar::Component) #

[View source]
def components=(components : Array(Scar::Component)) #

[View source]
def destroy #

Marks this entity for removal


[View source]
def has?(c : Component.class) : Bool #

Checks if this entity contains a component of the given type


[View source]
def has?(cs : Array(Component.class)) : Bool #

Checks if this entity contains a component of every given type


[View source]
def has?(*cs : Component.class) : Bool #

Checks if this entity contains a component of every given type


[View source]
def id : String #

[View source]
def z : Int32 #

Used to specify the rendering order


[View source]
def z=(z : Int32) #

Used to specify the rendering order


[View source]