File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 ;
Original file line number Diff line number Diff 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} ;
You can’t perform that action at this time.
0 commit comments