| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 | 
							- function TrinLayer() {
 
-     TrinLayer.superclass.constructor.apply(this);
 
-     this.autoReviveChildren = false;
 
-     this.children = null;
 
-     this.numChildren = 0;
 
-     this.sortIndex = "";
 
-     this.sortOrder = this.ASCEDING;
 
- }
 
- extend(TrinLayer, TrinBasic);
 
- TrinLayer.prototype.ASCEDNING = -1;
 
- TrinLayer.prototype.DESCENDING = 1;
 
- TrinLayer.prototype.DEPTH_ID = 0;
 
- TrinLayer.prototype.destroy = function() {
 
-     this.kill();
 
-     if (this.children !== null) {
 
-         var entity;
 
-         var i = 0;
 
-         while (i < this.numChildren) {
 
-             entity = this.children[i++];
 
-             if (entity !== null) {
 
-                 entity.destroy();
 
-             }
 
-         }
 
-         this.children = [];
 
-         this.numChildren = 0;
 
-         this.sortIndex = this.ASCEDING;
 
-         if (this.parent !== null) {
 
-             this.parent.remove(this);
 
-         }
 
-     }
 
-     TrinLayer.superclass.destroy.apply(this);
 
- };
 
- TrinLayer.prototype.kill = function() {
 
-     if (this.children !== null) {
 
-         var entity;
 
-         var i = 0;
 
-         while (i < this.numChildren) {
 
-             entity = this.children[i++];
 
-             if (entity !== null && entity.exists) {
 
-                 entity.kill();
 
-             }
 
-         }
 
-     }
 
-     TrinLayer.superclass.kill.apply(this);
 
- };
 
- TrinLayer.prototype.revive = function() {
 
-     TrinLayer.superclass.revive.apply(this);
 
-     if (this.autoReviveChildren && this.children !== null) {
 
-         var entity;
 
-         var i = 0;
 
-         while (i < this.numChildren) {
 
-             entity = this.children[i++];
 
-             if (entity !== null && !entity.exists) {
 
-                 entity.revive();
 
-             }
 
-         }
 
-     }
 
- };
 
- TrinLayer.prototype.update = function() {
 
-     TrinLayer.superclass.update.apply(this);
 
-     this.updateChildren();
 
- };
 
- TrinLayer.prototype.draw = function(context) {
 
-     this.drawChildren(context);
 
-     TrinLayer.superclass.draw.apply(this, [context]);
 
- };
 
- TrinLayer.prototype.sort = function(index, order) {
 
-     if (index === undefined) {
 
-         index = "y";
 
-     }
 
-     if (order === undefined) {
 
-         order = this.ASCEDING;
 
-     }
 
-     if (this.children !== null) {
 
-         this.sortIndex = index;
 
-         this.sortOrder = order;
 
-         this.children.sort(this.sortHandler);
 
-     }
 
- };
 
- TrinLayer.prototype.add = function(entity) {
 
-     if (this.children === null) {
 
-         this.children = [];
 
-     }
 
-     if (this.children.indexOf(entity) > -1) {
 
-         return entity;
 
-     }
 
-     if (entity.parent !== null) {
 
-         entity.parent.remove(entity);
 
-     }
 
-     entity.parent = this;
 
-     var i = 0;
 
-     var n = this.children.length;
 
-     while (i < n) {
 
-         if (this.children[i] === null) {
 
-             this.children[i] = entity;
 
-             return entity;
 
-         }
 
-         i++;
 
-     }
 
-     this.children[n] = entity;
 
-     this.numChildren++;
 
-     return entity;
 
- };
 
- TrinLayer.prototype.remove = function(entity, splice) {
 
-     if (this.children === null) {
 
-         return entity;
 
-     }
 
-     var i = this.children.indexOf(entity);
 
-     if (i < 0 || i >= this.children.length) {
 
-         return entity;
 
-     }
 
-     this.children[i] = null;
 
-     entity.parent = null;
 
-     if (splice) {
 
-         this.children.splice(i, 1);
 
-         this.numChildren--;
 
-     }
 
-     return entity;
 
- };
 
- TrinLayer.prototype.contains = function(entity) {
 
-     if (this.children === null) {
 
-         return false;
 
-     }
 
-     return (this.children.indexOf(entity) >= 0) ? true : false;
 
- };
 
- TrinLayer.prototype.recycle = function(_class) {
 
-     var entity = this.getAvailable(_class);
 
-     if (entity !== null) {
 
-         return entity;
 
-     }
 
-     if (_class === undefined || _class === null) {
 
-         return null;
 
-     }
 
-     entity = new _class();
 
-     return (entity instanceof TrinBasic) ? this.add(entity) : null;
 
- };
 
- TrinLayer.prototype.replace = function(oldEntity, newEntity) {
 
-     if (this.children === null) {
 
-         return newEntity;
 
-     }
 
-     var i = this.children.indexOf(oldEntity);
 
-     if (i >= 0 && i < this.children.length) {
 
-         if (newEntity.parent !== null && newEntity.parent !== this) {
 
-             newEntity.parent.remove(newEntity);
 
-             newEntity.parent = this;
 
-         }
 
-         this.children[i] = newEntity;
 
-         oldEntity.parent = null;
 
-     }
 
-     return newEntity;
 
- };
 
- TrinLayer.prototype.swap = function(entityA, entityB) {
 
-     if (this.children === null) {
 
-         return;
 
-     }
 
-     var iA = this.children.indexOf(entityA);
 
-     var iB = this.children.indexOf(entityB);
 
-     if (iA >= 0 && iA < this.children.length && iB >= 0 && iB < this.children.length)
 
-     {
 
-         this.children[iA] = entityB;
 
-         this.children[iB] = entityA;
 
-     }
 
- };
 
- TrinLayer.prototype.removeAll = function(destroy) {
 
-     if (destroy === undefined) {
 
-         destroy = true;
 
-     }
 
-     if (this.children === null) {
 
-         return;
 
-     }
 
-     var entity;
 
-     var i = 0;
 
-     while (i < this.numChildren) {
 
-         entity = this.children[i++];
 
-         if (entity !== null) {
 
-             if (destroy) {
 
-                 entity.destroy();
 
-             }
 
-             entity.parent = null;
 
-         }
 
-         this.children[i] = null;
 
-     }
 
-     this.numChildren = 0;
 
- };
 
- TrinLayer.prototype.getAvailable = function(_class) {
 
-     if (this.children === null) {
 
-         return null;
 
-     }
 
-     var entity;
 
-     var i = 0;
 
-     while (i < this.numChildren) {
 
-         entity = this.children[i++];
 
-         if (entity !== null && !entity.exists && ((_class === undefined) || (entity instanceof _class))) {
 
-             return entity;
 
-         }
 
-     }
 
-     return null;
 
- };
 
- TrinLayer.prototype.getExtant = function(_class) {
 
-     if (this.children === null) {
 
-         return null;
 
-     }
 
-     var entity;
 
-     var i = 0;
 
-     while (i < this.numChildren)
 
-     {
 
-         entity = this.children[i++];
 
-         if (entity !== null && entity.exists && ((_class === null) || (entity instanceof _class))) {
 
-             return entity;
 
-         }
 
-     }
 
-     return null;
 
- };
 
- TrinLayer.prototype.getAlive = function(_class) {
 
-     if (this.children === null) {
 
-         return null;
 
-     }
 
-     var entity;
 
-     var i = 0;
 
-     while (i < this.numChildren) {
 
-         entity = this.children[i++];
 
-         if (entity !== null && entity.exists && entity.alive &&
 
-                 ((_class === null) || (entity instanceof _class))) {
 
-             return entity;
 
-         }
 
-     }
 
-     return null;
 
- };
 
- TrinLayer.prototype.getDead = function(_class) {
 
-     if (this.children === null) {
 
-         return null;
 
-     }
 
-     var entity;
 
-     var i = 0;
 
-     while (i < this.numChildren) {
 
-         entity = this.children[i++];
 
-         if (entity !== null && !entity.alive &&
 
-                 ((_class === null) || (entity instanceof _class))) {
 
-             return entity;
 
-         }
 
-     }
 
-     return null;
 
- };
 
- TrinLayer.prototype.setAll = function(variableName, value, recurse) {
 
-     var entity;
 
-     var i = 0;
 
-     while (i < this.numChildren) {
 
-         entity = this.children[i++];
 
-         if (entity !== null) {
 
-             if (recurse && entity instanceof TrinLayer) {
 
-                 entity.setAll(variableName, value, recurse);
 
-             } else {
 
-                 entity[variableName] = value;
 
-             }
 
-         }
 
-     }
 
- };
 
- TrinLayer.prototype.callAll = function(functionName, args, recurse) {
 
-     var entity;
 
-     var i = 0;
 
-     while (i < this.numChildren) {
 
-         entity = this.children[i++];
 
-         if (entity !== null) {
 
-             if (recurse && entity instanceof TrinLayer) {
 
-                 entity.callAll(functionName, args, recurse);
 
-             } else if (typeof entity[functionName] === "function") {
 
-                 entity[functionName](args);
 
-             }
 
-         }
 
-     }
 
- };
 
- TrinLayer.prototype.updateChildren = function() {
 
-     if (this.children !== null) {
 
-         var entity;
 
-         var i = 0;
 
-         while (i < this.numChildren) {
 
-             entity = this.children[i++];
 
-             if (entity !== null && entity.exists) {
 
-                 if (entity.active) {
 
-                     entity.update();
 
-                 }
 
-             }
 
-         }
 
-     }
 
- };
 
- TrinLayer.prototype.drawChildren = function(context) {
 
-     if (this.children !== null) {
 
-         var entity;
 
-         var i = 0;
 
-         while (i < this.numChildren) {
 
-             entity = this.children[i++];
 
-             if (entity !== null && entity.exists && entity.visible) {
 
-                 entity.draw(context);
 
-             }
 
-         }
 
-     }
 
- };
 
- TrinLayer.prototype.sortLayer = function(entity1, entity2) {
 
-     if (entity1 === null) {
 
-         return this.sortOrder;
 
-     } else if (entity2 === null) {
 
-         return -this.sortOrder;
 
-     }
 
-     if (entity1[this.sortIndex] < entity2[this.sortIndex]) {
 
-         return this.sortOrder;
 
-     } else if (entity1[this.sortIndex] > entity2[this.sortIndex]) {
 
-         return -this.sortOrder;
 
-     }
 
-     return 0;
 
- };
 
 
  |