|
| 1 | +/** |
| 2 | + * @author Richard Davey <rich@photonstorm.com> |
| 3 | + * @copyright 2019 Photon Storm Ltd. |
| 4 | + * @license {@link https://opensource.org/licenses/MIT|MIT License} |
| 5 | + */ |
| 6 | + |
| 7 | +var PropertyValueSet = require('./PropertyValueSet'); |
| 8 | + |
| 9 | +/** |
| 10 | + * Takes an array of Game Objects, or any objects that have the public properties `scrollFactorX` and `scrollFactorY` |
| 11 | + * and then sets them to the given values. |
| 12 | + * |
| 13 | + * The optional `stepX` and `stepY` properties are applied incrementally, multiplied by each item in the array. |
| 14 | + * |
| 15 | + * To use this with a Group: `SetScrollFactor(group.getChildren(), scrollFactorX, scrollFactorY, stepX, stepY)` |
| 16 | + * |
| 17 | + * @function Phaser.Actions.SetScrollFactor |
| 18 | + * @since 3.0.0 |
| 19 | + * |
| 20 | + * @generic {Phaser.GameObjects.GameObject[]} G - [items,$return] |
| 21 | + * |
| 22 | + * @param {(array|Phaser.GameObjects.GameObject[])} items - The array of items to be updated by this action. |
| 23 | + * @param {number} scrollFactorX - The amount to set the `scrollFactorX` property to. |
| 24 | + * @param {number} [scrollFactorY] - The amount to set the `scrollFactorY` property to. If `undefined` or `null` it uses the `scrollFactorX` value. |
| 25 | + * @param {number} [stepX=0] - This is added to the `scrollFactorX` amount, multiplied by the iteration counter. |
| 26 | + * @param {number} [stepY=0] - This is added to the `scrollFactorY` amount, multiplied by the iteration counter. |
| 27 | + * @param {integer} [index=0] - An optional offset to start searching from within the items array. |
| 28 | + * @param {integer} [direction=1] - The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. |
| 29 | + * |
| 30 | + * @return {(array|Phaser.GameObjects.GameObject[])} The array of objects that were passed to this Action. |
| 31 | + */ |
| 32 | +var SetScrollFactor = function (items, scrollFactorX, scrollFactorY, stepX, stepY, index, direction) |
| 33 | +{ |
| 34 | + if (scrollFactorY === undefined || scrollFactorY === null) { scrollFactorY = scrollFactorX; } |
| 35 | + |
| 36 | + PropertyValueSet(items, 'scrollFactorX', scrollFactorX, stepX, index, direction); |
| 37 | + |
| 38 | + return PropertyValueSet(items, 'scrollFactorY', scrollFactorY, stepY, index, direction); |
| 39 | +}; |
| 40 | + |
| 41 | +module.exports = SetScrollFactor; |
0 commit comments