Skip to content

Commit add3184

Browse files
committed
Add Phaser.Actions.WrapInRectangle
1 parent 935a893 commit add3184

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

src/actions/WrapInRectangle.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2018 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
var Wrap = require('../math/Wrap');
8+
9+
/**
10+
* Wrap each item's coordinates within a rectangle's area.
11+
*
12+
* @function Phaser.Actions.WrapInRectangle
13+
* @since [version]
14+
* @see Phaser.Math.Wrap
15+
*
16+
* @param {array} items - An array of Game Objects. The contents of this array are updated by this Action.
17+
* @param {Phaser.Geom.Rectangle} rect - The rectangle.
18+
* @param {number} [padding=0] - An amount added to each side of the rectangle during the operation.
19+
*
20+
* @return {array} The array of Game Objects that was passed to this Action.
21+
*/
22+
var WrapInRectangle = function (items, rect, padding)
23+
{
24+
if (padding === undefined)
25+
{
26+
padding = 0;
27+
}
28+
29+
for (var i = 0; i < items.length; i++)
30+
{
31+
var item = items[i];
32+
33+
item.x = Wrap(item.x, rect.left - padding, rect.right + padding);
34+
item.y = Wrap(item.y, rect.top - padding, rect.bottom + padding);
35+
}
36+
37+
return items;
38+
};
39+
40+
module.exports = WrapInRectangle;

src/actions/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ module.exports = {
5454
SmootherStep: require('./SmootherStep'),
5555
SmoothStep: require('./SmoothStep'),
5656
Spread: require('./Spread'),
57-
ToggleVisible: require('./ToggleVisible')
57+
ToggleVisible: require('./ToggleVisible'),
58+
WrapInRectangle: require('./WrapInRectangle')
5859

5960
};

0 commit comments

Comments
 (0)