mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 13:13:43 +00:00
Add Phaser.Actions.WrapInRectangle
This commit is contained in:
parent
935a89342d
commit
add318491f
2 changed files with 42 additions and 1 deletions
40
src/actions/WrapInRectangle.js
Normal file
40
src/actions/WrapInRectangle.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2018 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
var Wrap = require('../math/Wrap');
|
||||
|
||||
/**
|
||||
* Wrap each item's coordinates within a rectangle's area.
|
||||
*
|
||||
* @function Phaser.Actions.WrapInRectangle
|
||||
* @since [version]
|
||||
* @see Phaser.Math.Wrap
|
||||
*
|
||||
* @param {array} items - An array of Game Objects. The contents of this array are updated by this Action.
|
||||
* @param {Phaser.Geom.Rectangle} rect - The rectangle.
|
||||
* @param {number} [padding=0] - An amount added to each side of the rectangle during the operation.
|
||||
*
|
||||
* @return {array} The array of Game Objects that was passed to this Action.
|
||||
*/
|
||||
var WrapInRectangle = function (items, rect, padding)
|
||||
{
|
||||
if (padding === undefined)
|
||||
{
|
||||
padding = 0;
|
||||
}
|
||||
|
||||
for (var i = 0; i < items.length; i++)
|
||||
{
|
||||
var item = items[i];
|
||||
|
||||
item.x = Wrap(item.x, rect.left - padding, rect.right + padding);
|
||||
item.y = Wrap(item.y, rect.top - padding, rect.bottom + padding);
|
||||
}
|
||||
|
||||
return items;
|
||||
};
|
||||
|
||||
module.exports = WrapInRectangle;
|
|
@ -54,6 +54,7 @@ module.exports = {
|
|||
SmootherStep: require('./SmootherStep'),
|
||||
SmoothStep: require('./SmoothStep'),
|
||||
Spread: require('./Spread'),
|
||||
ToggleVisible: require('./ToggleVisible')
|
||||
ToggleVisible: require('./ToggleVisible'),
|
||||
WrapInRectangle: require('./WrapInRectangle')
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue