Skip to content
Ezelia edited this page Jan 9, 2014 · 1 revision

A component is an object that hold data. it is instanciated when attached to an entity.

Defining a component in TypeScript

class CSkin implements eee.IComponent {
    static __label__ = 'skin'; //this is the group name
 
    public visible: boolean = true;
    constructor(
        public src: string
        ) {}
}

Defining a component in JavaScript

    function CSkin (src) {
        this.src = src;
        this.visible = true;
    }
    CSkin.__label__ = 'skin';

The __ label __ static member

this is a special member used internally by EEE to identify instances of a given component. this property have to be unique.

this label is also used as the entity member name holding the object instance.

if you don't set __ label __, EEE will affect a default name based on the object type name.

suppose we have the following player entity

var player = new eee.Entity();
player.add(new CSkin('path/to/img.png'));

at this point if we have set __ label __ value to "skin", the player object will look like.

player = {
  skin : {
      src : 'path/to/img.png',
      visible : true
  }
}

if __ label __ is not set , the player object will look like.

player = {
  CSkin : {
      src : 'path/to/img.png',
      visible : true
  }
}