Skip to content

Commit a7f46a7

Browse files
committed
Added ShiftPosition Action and Layer.getLength.
1 parent 730c6b5 commit a7f46a7

4 files changed

Lines changed: 102 additions & 1 deletion

File tree

v3/src/actions/ShiftPosition.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Iterate through items changing the position of each element to
2+
// be that of the element that came before it in the array (or after it if direction = 1)
3+
// The first items position is set to x/y.
4+
5+
var ShiftPosition = function (items, x, y, direction)
6+
{
7+
if (direction === undefined) { direction = 0; }
8+
9+
if (items.length > 1)
10+
{
11+
var i;
12+
var cx;
13+
var cy;
14+
var px;
15+
var py;
16+
var cur;
17+
18+
if (direction === 0)
19+
{
20+
// Bottom to Top
21+
22+
var len = items.length - 1;
23+
24+
px = items[len].x;
25+
py = items[len].y;
26+
27+
for (i = len - 1; i >= 0; i--)
28+
{
29+
// Current item
30+
cur = items[i];
31+
32+
// Get current item x/y, to be passed to the next item in the list
33+
cx = cur.x;
34+
cy = cur.y;
35+
36+
// Set current item to the previous items x/y
37+
cur.x = px;
38+
cur.y = py;
39+
40+
// Set current as previous
41+
px = cx;
42+
py = cy;
43+
}
44+
45+
// Update the head item to the new x/y coordinates
46+
items[len].x = x;
47+
items[len].y = y;
48+
}
49+
else
50+
{
51+
// Top to Bottom
52+
53+
px = items[0].x;
54+
py = items[0].y;
55+
56+
for (i = 1; i < items.length; i++)
57+
{
58+
// Current item
59+
cur = items[i];
60+
61+
// Get current item x/y, to be passed to the next item in the list
62+
cx = cur.x;
63+
cy = cur.y;
64+
65+
// Set current item to the previous items x/y
66+
cur.x = px;
67+
cur.y = py;
68+
69+
// Set current as previous
70+
px = cx;
71+
py = cy;
72+
}
73+
74+
// Update the head item to the new x/y coordinates
75+
items[0].x = x;
76+
items[0].y = y;
77+
}
78+
}
79+
else
80+
{
81+
items[0].x = x;
82+
items[0].y = y;
83+
}
84+
85+
return items;
86+
};
87+
88+
module.exports = ShiftPosition;

v3/src/actions/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module.exports = {
3535
SetX: require('./SetX'),
3636
SetXY: require('./SetXY'),
3737
SetY: require('./SetY'),
38+
ShiftPosition: require('./ShiftPosition'),
3839
SmootherStep: require('./SmootherStep'),
3940
SmoothStep: require('./SmoothStep'),
4041
Spread: require('./Spread'),

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: '531e9860-521e-11e7-914d-2dba089add27'
2+
build: '8abd9c10-52c0-11e7-b265-8776d98a5edd'
33
};
44
module.exports = CHECKSUM;

v3/src/gameobjects/layer/Layer.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ var Layer = new Class({
170170
return this.children.entries;
171171
},
172172

173+
getLength: function ()
174+
{
175+
return this.children.size;
176+
},
177+
173178
destroy: function ()
174179
{
175180
this.children.clear();
@@ -404,6 +409,13 @@ var Layer = new Class({
404409
return this;
405410
},
406411

412+
shiftPosition: function (x, y, direction)
413+
{
414+
Actions.ShiftPosition(this.children.entries, x, y, direction);
415+
416+
return this;
417+
},
418+
407419
smootherStep: function (property, min, max, inc)
408420
{
409421
Actions.SmootherStep(this.children.entries, property, min, max, inc);

0 commit comments

Comments
 (0)