Skip to content
Rogan Murley edited this page Sep 17, 2015 · 20 revisions

An Entity represents the state of something in the game. It could represent something tangible, like a player, enemy or obstacle, or something intangible like a score or timer. They are made of 'building blocks' called Components.

Usage

var world = new hitagi.World();
var entity = new hitagi.Entity()
    .attach(new hitagi.components.Position({
        x: 0,
        y: 0
    }))
    .attach(new hitagi.components.graphics.Graphic()
    .attach(new hitagi.components.graphics.Rectangle({
        width: 32,
        height: 32,
        color: 0xffffff
    })));
world.add(entity);

Constructor

parameters:
    none

Properties

c: Exposes attached Components for easy access as a sealed object mapping Component IDs to Components.

{
    string: component
}

uid: Unique identifier (UID) automatically generated by constructor. Used by the World and Systems to identify the Entity.

string

world: Reference to the World an entity has been added to, else null.

World object

Methods

attach: Attaches a Component to the Entity, throws an error if it's dependencies are not satisfied.

parameters:
    component - Component to be attached to Entity.
return: Entity, for chaining

detach: Detaches a Component from an Entity. Throws an error if the Entity's components no longer satisfy their dependencies.

parameters:
    componentID - ID of component to be detached from Entity.
return: Entity, for chaining

has: Checks if an Entity has the given Component attached.

parameters:
    componentID - Component to check for.
return: Boolean
Clone this wiki locally