Skip to content

Commit 5a871fc

Browse files
committed
Added GetFirst Action and bound to Layer.
1 parent 639e6a1 commit 5a871fc

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

v3/src/actions/GetFirst.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// compare = Object:
2+
// {
3+
// scaleX: 0.5,
4+
// scaleY: 1
5+
// }
6+
7+
var GetFirst = function (items, compare, index)
8+
{
9+
for (var i = index; i < items.length; i++)
10+
{
11+
var item = items[i];
12+
13+
var match = true;
14+
15+
for (var property in compare)
16+
{
17+
if (item[property] !== compare[property])
18+
{
19+
match = false;
20+
}
21+
}
22+
23+
if (match)
24+
{
25+
return item;
26+
}
27+
}
28+
29+
return null;
30+
};
31+
32+
module.exports = GetFirst;

v3/src/actions/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = {
44

55
Angle: require('./Angle'),
66
Call: require('./Call'),
7+
GetFirst: require('./GetFirst'),
78
GridAlign: require('./GridAlign'),
89
IncAlpha: require('./IncAlpha'),
910
IncX: require('./IncX'),

v3/src/gameobjects/layer/Layer.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ var Layer = new Class({
175175
return this.children.size;
176176
},
177177

178+
getFirst: function (compare, index)
179+
{
180+
if (index === undefined) { index = 0; }
181+
182+
return Actions.GetFirst(this.children.entries, compare, index);
183+
},
184+
178185
destroy: function ()
179186
{
180187
this.children.clear();

0 commit comments

Comments
 (0)