Skip to content

Instantly share code, notes, and snippets.

@piayo
Last active December 15, 2015 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piayo/5202815 to your computer and use it in GitHub Desktop.
Save piayo/5202815 to your computer and use it in GitHub Desktop.
PIXI.DisplayObjectContainer.prototype.find
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;
}
@piayo
Copy link
Author

piayo commented Mar 20, 2013

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]

@piayo
Copy link
Author

piayo commented Mar 20, 2013

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