spinnerbox Posted September 8, 2016 Share Posted September 8, 2016 I was wondering is there some function in Phaser that will return child of a graphics object by its name? I don't see one. But I see getChildAt() or getChildIndex(). Link to comment Share on other sites More sharing options...
Str1ngS Posted September 8, 2016 Share Posted September 8, 2016 That's because children don't have names, nor are they refenced by such a thing. They are basicly just a list of objects. Link to comment Share on other sites More sharing options...
spinnerbox Posted September 8, 2016 Author Share Posted September 8, 2016 Ok. Phaser.Graphics has a property name but... Quote A user defined name given to this Game Object. This value isn't ever used internally by Phaser, it is meant as a game level property. Ok, then if I don't bother with name how do I get certain child? By using names I should create "for" loop and search for what I want, but is this the best way? EDIT: Meh, whatever, will type my own getChildByName() function Link to comment Share on other sites More sharing options...
spinnerbox Posted September 8, 2016 Author Share Posted September 8, 2016 var getChildByName = function (grObject, name) { var i = 0, children = grObject.children, child = null; for (i = 0; i < children.length; i += 1) { if (children[i].name === name) { child = children[i]; break; } } return child; }; Link to comment Share on other sites More sharing options...
Recommended Posts