An entity is the basic element in a game world. More...
Public Member Functions | |
number | GetID () |
Returns the ID of this entity. More... | |
AddChild (entity child) | |
This method adds the given entity to the children of this entity. More... | |
RemoveChild (entity child) | |
This method removes the given entity from the children of this entity. More... | |
EntityT | GetParent () |
This method returns the parent of this entity (or nil if there is no parent). More... | |
EntityT | GetRoot () |
Returns the top-most parent of this entity, that is, the root of the hierarchy that this entity is in. More... | |
table | GetChildren () |
This method returns an array of the children of this entity. More... | |
EntityT | FindByID (number ID) |
Finds the entity with the given ID in the hierachy tree of this entity. More... | |
EntityT | FindByName (string Name) |
Finds the entity with the given name in the hierachy tree of this entity. More... | |
table | FindByComponent (string TypeName) |
Finds all entities in the hierachy tree of this entity that have at least one component of the given (type) name. More... | |
ComponentBasicsT | GetBasics () |
This method returns the "Basics" component of this entity. More... | |
ComponentTransformT | GetTransform () |
This method returns the "Transform" component of this entity. More... | |
AddComponent (ComponentBaseT component) | |
This method adds a component to this entity. More... | |
RemoveComponent (ComponentBaseT component) | |
This method removes a component from this entity. More... | |
table | GetComponents () |
This method returns an array of the components of this entity. More... | |
ComponentBaseT | GetComponent (string type_name, number n) |
This method returns the (n-th) component of the given (type) name. More... | |
Event Handlers (Callbacks) | |
See the Event Handlers (Callbacks) overview page for additional information about the methods in this group. | |
OnInit () | |
This method is called for each entity when a new world is loaded. More... | |
An entity is the basic element in a game world.
Entity can be hierarchically arranged in parent/child relationships, e.g. a player that rides a car.
An entity is a separate unit that is self-contained and has its own identity, but has very little own features. Instead, an entity contains a set of components, each of which implements a specific feature for the entity.
If you would like to create a new entity explicitly (those defined in the CaWE Map Editor are instantiated automatically), use WorldT::new():
AddChild | ( | entity | child | ) |
This method adds the given entity to the children of this entity.
AddComponent | ( | ComponentBaseT | component | ) |
This method adds a component to this entity.
table FindByComponent | ( | string | TypeName | ) |
Finds all entities in the hierachy tree of this entity that have at least one component of the given (type) name.
Use GetRoot():FindByComponent("xy")
in order to search the entire world for entities with component xy
.
TypeName | The type name of the component that found entities must have |
EntityT FindByID | ( | number | ID | ) |
Finds the entity with the given ID in the hierachy tree of this entity.
Use GetRoot():Find(xy)
in order to search the entire world for the entity with ID xy
.
ID | The ID of the entity that is to be found. |
nil
if no entity with this ID exists. EntityT FindByName | ( | string | Name | ) |
Finds the entity with the given name in the hierachy tree of this entity.
Use GetRoot():Find("xy")
in order to search the entire world for the entity with name xy
.
Name | The name of the entity that is to be found. |
nil
if no entity with this name exists. ComponentBasicsT GetBasics | ( | ) |
This method returns the "Basics" component of this entity.
table GetChildren | ( | ) |
This method returns an array of the children of this entity.
ComponentBaseT GetComponent | ( | string | type_name, |
number | n | ||
) |
This method returns the (n-th) component of the given (type) name.
Covers the "custom" components as well as the application components, "Basics" and "Transform". That is, GetComponent("Basics") == GetBasics()
and GetComponent("Transform") == GetTransform()
.
type_name | The (type) name of the component to get, e.g. "Image". |
n | This parameter is optional, it defaults to 0 if not given. |
table GetComponents | ( | ) |
This method returns an array of the components of this entity.
number GetID | ( | ) |
Returns the ID of this entity.
The ID is unique in the world, and is used (in C++ code) to unambiguously identify the entity in network messages and as entity index number into .cw
world files.
EntityT GetParent | ( | ) |
This method returns the parent of this entity (or nil
if there is no parent).
EntityT GetRoot | ( | ) |
Returns the top-most parent of this entity, that is, the root of the hierarchy that this entity is in.
ComponentTransformT GetTransform | ( | ) |
This method returns the "Transform" component of this entity.
OnInit | ( | ) |
This method is called for each entity when a new world is loaded.
Note that these OnInit() methods are automatically written by the Cafu Map Editor into a world's .cent
files, you normally don't write them yourself. Use the ComponentBaseT::OnInit() methods instead for custom dynamic initialization.
RemoveChild | ( | entity | child | ) |
This method removes the given entity from the children of this entity.
child | The entity that is to be removed from the children of this entity. |
RemoveComponent | ( | ComponentBaseT | component | ) |
This method removes a component from this entity.