Added GetFirst Action and bound to Layer.

This commit is contained in:
photonstorm 2017-06-19 14:38:22 +01:00
parent 639e6a14c5
commit 5a871fcabe
3 changed files with 40 additions and 0 deletions

View 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;

View file

@ -4,6 +4,7 @@ module.exports = {
Angle: require('./Angle'),
Call: require('./Call'),
GetFirst: require('./GetFirst'),
GridAlign: require('./GridAlign'),
IncAlpha: require('./IncAlpha'),
IncX: require('./IncX'),

View file

@ -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();