lib/game.js
function(entity) {
  // Bind to start event right away.
  var boundStart = entity.start.bind(entity);
  this.on('start', boundStart);
  // Bind to preloadComplete, but only once.
  var boundPreloadComplete = entity.preloadComplete.bind(entity);
  this.once('preloadComplete', boundPreloadComplete);
  // Only bind to update after preloadComplete event.
  var boundUpdate = entity.update.bind(entity);
  this.once('preloadComplete', function() {
    this.on('update', boundUpdate);
  }.bind(this));
  entity.on('destroy', function() {
    this.removeListener('start', boundStart);
    this.removeListener('preloadComplete', boundPreloadComplete);
    this.removeListener('update', boundUpdate);
  }.bind(this));
  this.emit('entityAdded', entity);
}
function(entity) {
  // Bind to start event right away.
  var boundStart = entity.start.bind(entity);
  this.on('start', boundStart);
  // Bind to preloadComplete, but only once.
  var boundPreloadComplete = entity.preloadComplete.bind(entity);
  this.once('preloadComplete', boundPreloadComplete);
  // Only bind to update after preloadComplete event.
  var boundUpdate = entity.update.bind(entity);
  this.once('preloadComplete', function() {
    this.on('update', boundUpdate);
  }.bind(this));
  entity.on('destroy', function() {
    this.removeListener('start', boundStart);
    this.removeListener('preloadComplete', boundPreloadComplete);
    this.removeListener('update', boundUpdate);
  }.bind(this));
  this.emit('entityAdded', entity);
}
function ( entity ) { // Bind to start event right away. var boundStart = entity . start . bind ( entity ) ; this . on ( 'start' , boundStart ) ; // Bind to preloadComplete, but only once. var boundPreloadComplete = entity . preloadComplete . bind ( entity ) ; this . once ( 'preloadComplete' , boundPreloadComplete ) ; // Only bind to update after preloadComplete event. var boundUpdate = entity . update . bind ( entity ) ; this . once ( 'preloadComplete' , function ( ) { this . on ( 'update' , boundUpdate ) ; } . bind ( this ) ) ; entity . on ( 'destroy' , function ( ) { this . removeListener ( 'start' , boundStart ) ; this . removeListener ( 'preloadComplete' , boundPreloadComplete ) ; this . removeListener ( 'update' , boundUpdate ) ; } . bind ( this ) ) ; this . emit ( 'entityAdded' , entity ) ; }
Bound to a game instance, will add a single entity.
Bound to a game instance will add a single entity .