Last active
December 15, 2015 04:39
-
-
Save piayo/5202815 to your computer and use it in GitHub Desktop.
PIXI.DisplayObjectContainer.prototype.find
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PIXI.DisplayObjectContainer.prototype.find = function(reg, limit){ | |
var reg = new RegExp(reg); | |
var arr = []; | |
for(var i=0;i<this.children.length;i++){ | |
if(this.children[i].name){ | |
var n = this.children[i].name.toString(); | |
if(reg.test(n) == true){ | |
arr.push(this.children[i]); | |
if(limit && arr.length >= limit){ | |
return arr; | |
} | |
} | |
} | |
} | |
return arr; | |
} |
i want to add param "typeof" from Texture, Sprite, MovieClip.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mc0.name = "enemy1";
mc1.name = "enemy1";
mc2.name = "enemy2";
...
stage.addChild(mc0);
stage.addChild(mc1);
stage.addChild(mc2);
...
//get enemis by name Strings
var enemis = stage.find("enemy", 2);
console.log(enemis)
//[PIXI.Sprite, PIXI.Sprite]