IgeObject

Method: addBehaviour

Adds a behaviour to the object's active behaviour list.
addBehaviour (String id, Function behaviour, Boolean duringTick)
  • Stringid
  • Functionbehaviour
  • BooleanduringTick If true, will execute the behaviour during the tick() method instead of the update() method.
Returns * Returns this on success or false on failure.

Add a behaviour with the id "myBehaviour"

var entity = new IgeEntity();
entity.addBehaviour('myBehaviour', function () {
    // Code here will execute during each engine update for
    // this entity. I can access the entity via the "this"
    // keyword such as:
    this._somePropertyOfTheEntity = 'moo';
});

// Now since each update we are setting _somePropertyOfTheEntity
// to equal "moo" we can console log the property and get
// the value as "moo"
console.log(entity._somePropertyOfTheEntity);
© Copyright 2013 Irrelon Software Limited. All Rights Reserved. UK Registered Company Number: 07522767
Isogenic (ī´sōjen´ik): Adj originating from a common source; possessing the same genetic composition.
Strange Things Happen at the One Two Point