PackagePBLabs.Engine.Entity
Interfacepublic interface IEntity extends IPropertyBag
ImplementorsEntityComponent

Game objects in PBE are referred to as entities. This interface defines the behavior for an entity. A full featured implementation of this interface is included, but is hidden so as to force using IEntity when storing references to entities. To create a new entity, use AllocateEntity.

An entity by itself is a very light weight object. All it needs to store is its name and a list of components. Custom functionality is added by creating components and attaching them to entities.

An event with type "EntityDestroyed" will be fired when the entity is destroyed via the Destroy() method. This event is fired before any cleanup is done.

See also

IEntityComponent
PBLabs.Engine.Entity.AllocateEntity()


Public Properties
 PropertyDefined by
 InheritedEventDispatcher : IEventDispatcher
The event dispatcher that controls events for this entity.
IPropertyBag
  Name : String
[read-only] The name of the entity.
IEntity
Public Methods
 MethodDefined by
  
AddComponent(component:IEntityComponent, componentName:String):void
Adds a component to the entity.
IEntity
  
Deserialize(xml:XML, registerComponents:Boolean = true):void
Sets up this entity from an xml description.
IEntity
  
Destroy():void
Destroys the entity by removing all components and unregistering it from the name manager.
IEntity
 Inherited
Checks whether a property exists on this entity.
IPropertyBag
 Inherited
Gets the value of a property on this entity.
IPropertyBag
  
Initialize(name:String, alias:String = null):void
Initializes the entity, optionally assigning it a name.
IEntity
  
LookupComponentByName(componentName:String):IEntityComponent
Gets a component that was registered with a specific name on this entity.
IEntity
  
Gets a component of a specific type from this entity.
IEntity
  
LookupComponentsByType(componentType:Class):Array
Gets a list of all the components of a specific type that are on this entity.
IEntity
  
Removes a component from the entity.
IEntity
  
Serialize(xml:XML):void
Creates an XML description of this entity, including all currently attached components.
IEntity
 Inherited
SetProperty(property:PropertyReference, value:*):void
Sets the value of a property on this entity.
IPropertyBag
Property detail
Nameproperty
Name:String  [read-only]

The name of the entity. This is set by passing a name to the Initialize method after the entity is first created.

Implementation
    public function get Name():String

See also

Method detail
AddComponent()method
public function AddComponent(component:IEntityComponent, componentName:String):void

Adds a component to the entity.

When a component is added, it will have its Register method called (or _OnAdd if it is derived from EntityComponent). Also, Reset will be called on all components currently attached to the entity (or _OnReset if it is derived from EntityComponent).

Parameters
component:IEntityComponent — The component to add.
 
componentName:String — The name to set for the component. This is the value to use in LookupComponentByName to get a reference to the component. The name must be unique across all components on this entity.
Deserialize()method 
public function Deserialize(xml:XML, registerComponents:Boolean = true):void

Sets up this entity from an xml description.

Parameters
xml:XML — The xml object describing the entity.
 
registerComponents:Boolean (default = true) — Set this to false to add components to the entity without registering them. This is used by the level manager to facilitate creating entities from templates.

See also

Destroy()method 
public function Destroy():void

Destroys the entity by removing all components and unregistering it from the name manager.

Currently this will not invalidate external references to the entity so the entity will only be cleaned up by the garbage collector if those are set to null manually.

Initialize()method 
public function Initialize(name:String, alias:String = null):void

Initializes the entity, optionally assigning it a name. This should be called immediately after the entity is created.

Parameters
name:String — The name to assign to the entity. If this is null or an empty string, the entity will not register itself with the name manager.
 
alias:String (default = null) — An alternate name under which this entity can be looked up. Useful when you need to distinguish between multiple things but refer to the active one by a consistent name.

See also

LookupComponentByName()method 
public function LookupComponentByName(componentName:String):IEntityComponent

Gets a component that was registered with a specific name on this entity.

Parameters
componentName:String — The name of the component to retrieve. This corresponds to the second parameter passed to AddComponent.

Returns
IEntityComponent — The component with the specified name.

See also

LookupComponentByType()method 
public function LookupComponentByType(componentType:Class):IEntityComponent

Gets a component of a specific type from this entity. If more than one component of a specific type exists, there is no guarantee which one will be returned. To retrieve all components of a specified type, use LookupComponentsByType.

Parameters
componentType:Class — The type of the component to retrieve.

Returns
IEntityComponent — The component, or null if none of the specified type were found.

See also

LookupComponentsByType()method 
public function LookupComponentsByType(componentType:Class):Array

Gets a list of all the components of a specific type that are on this entity.

Parameters
componentType:Class — The type of components to retrieve.

Returns
Array — An array containing all the components of the specified type on this entity.
RemoveComponent()method 
public function RemoveComponent(component:IEntityComponent):void

Removes a component from the entity.

When a component is removed, it will have its Unregister method called (or _OnRemove if it is derived from EntityComponent). Also, Reset will be called on all components currently attached to the entity (or _OnReset if it is derived from EntityComponent).

Parameters
component:IEntityComponent — The component to remove.
Serialize()method 
public function Serialize(xml:XML):void

Creates an XML description of this entity, including all currently attached components.

This is not implemented yet.

Parameters
xml:XML — The xml object describing the entity. The parent tag should be included in this variable when the function is called, so only child tags need to be created.

See also