mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 13:13:43 +00:00
Added GetFirst Action and bound to Layer.
This commit is contained in:
parent
639e6a14c5
commit
5a871fcabe
3 changed files with 40 additions and 0 deletions
32
v3/src/actions/GetFirst.js
Normal file
32
v3/src/actions/GetFirst.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
// compare = Object:
|
||||
// {
|
||||
// scaleX: 0.5,
|
||||
// scaleY: 1
|
||||
// }
|
||||
|
||||
var GetFirst = function (items, compare, index)
|
||||
{
|
||||
for (var i = index; i < items.length; i++)
|
||||
{
|
||||
var item = items[i];
|
||||
|
||||
var match = true;
|
||||
|
||||
for (var property in compare)
|
||||
{
|
||||
if (item[property] !== compare[property])
|
||||
{
|
||||
match = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (match)
|
||||
{
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
module.exports = GetFirst;
|
|
@ -4,6 +4,7 @@ module.exports = {
|
|||
|
||||
Angle: require('./Angle'),
|
||||
Call: require('./Call'),
|
||||
GetFirst: require('./GetFirst'),
|
||||
GridAlign: require('./GridAlign'),
|
||||
IncAlpha: require('./IncAlpha'),
|
||||
IncX: require('./IncX'),
|
||||
|
|
|
@ -175,6 +175,13 @@ var Layer = new Class({
|
|||
return this.children.size;
|
||||
},
|
||||
|
||||
getFirst: function (compare, index)
|
||||
{
|
||||
if (index === undefined) { index = 0; }
|
||||
|
||||
return Actions.GetFirst(this.children.entries, compare, index);
|
||||
},
|
||||
|
||||
destroy: function ()
|
||||
{
|
||||
this.children.clear();
|
||||
|
|
Loading…
Reference in a new issue