abstract class Entitas::Component
- Entitas::Component
- Reference
- Object
Overview
Inherit this class if you want to create a component which you can add to an entity. Optionally, you can add these attributes: @[Component::Unique]: the code generator will generate additional methods for the context to ensure that only one entity with this component exists. E.g. context.is_animating = true or context.SetResources(); @[Context(MyContextName), Context(MyOtherContextName)]: You can make this component to be available only in the specified contexts.
@[Component::Unique, Context(Game), Context(User)]
class Foo < Entitas::Component
prop :size, Int32
prop :default, String, default: "foo"
end
Conmponets can also be declared using existing classes without inheritance.
The special macro property_alias
will need to be used to alias any pre-existing methods as
component values
@[Context(Test3)]
class Vector3 < Array(Int32)
property_alias :size, Int32, default: 0
define_property :age, Int32, default: 0
end
Included Modules
Defined in:
entitas.crentitas/component.cr
entitas/generators/component.cr
entitas/macros/component.cr
Constant Summary
-
COMPONENT_KLASSES =
[] of Entitas::Component::ComponentTypes
-
COMPONENT_NAMES =
COMPONENT_TO_INDEX_MAP.keys.map(&.to_s)
-
COMPONENT_TO_INDEX_MAP =
{} of Entitas::Component::ComponentTypes => Index
-
INDEX_TO_COMPONENT_MAP =
{} of Index => Entitas::Component::ComponentTypes
-
TOTAL_COMPONENTS =
0
-
The total number of componets
Class Method Summary
Instance Method Summary
-
#total_components : Int32
The total amount of components an entity can possibly have.