Skip to content

Commit ecbff44

Browse files
committed
Group.getByName searches the Group for the first instance of a child with the name property matching the given argument. Should more than one child have the same name only the first instance is returned.
1 parent 65f8f11 commit ecbff44

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
325325
* Polygon now takes an array of arrays as a new type when constructing it: `[[x1, y1], [x2, y2]]` (thanks @ShimShamSam #2360)
326326
* Text has a new property `maxLines` which is the maximum number of lines to be shown for wrapped text. If set to 0 (the default) there is limit. This prevents wrapped text from overflowing on a fixed layout (thanks @slashman #2410)
327327
* `outOfCameraBoundsKill` is a new boolean property that all Game Objects with the `InWorld` component has. If `autoCull` and this property are both `true` then the Object will be automatically killed if it leaves the camera bounds (thanks @jakewilson #2402)
328+
* Group.getByName searches the Group for the first instance of a child with the `name` property matching the given argument. Should more than one child have the same name only the first instance is returned.
328329

329330
### Updates
330331

src/core/Group.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,29 @@ Phaser.Group.prototype.getIndex = function (child) {
799799

800800
};
801801

802+
/**
803+
* Searches the Group for the first instance of a child with the `name`
804+
* property matching the given argument. Should more than one child have
805+
* the same name only the first instance is returned.
806+
*
807+
* @method Phaser.Group#getByName
808+
* @param {string} name - The name to search for.
809+
* @return {any} The first child with a matching name, or null if none were found.
810+
*/
811+
Phaser.Group.prototype.getByName = function (name) {
812+
813+
for (var i = 0; i < this.children.length; i++)
814+
{
815+
if (this.children[i].name === name)
816+
{
817+
return this.children[i];
818+
}
819+
}
820+
821+
return null;
822+
823+
};
824+
802825
/**
803826
* Replaces a child of this group with the given newChild. The newChild cannot be a member of this group.
804827
*

0 commit comments

Comments
 (0)