Skip to content

Commit 171ca39

Browse files
authored
Merge pull request phaserjs#4847 from rexrainbow/Action-of-scrollFactor
Add SetScrollFactor into Action and Group's createFromConfig
2 parents 392fd0a + 53e9fd1 commit 171ca39

6 files changed

Lines changed: 136 additions & 0 deletions

File tree

src/actions/SetScrollFactor.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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;

src/actions/SetScrollFactorX.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 property `scrollFactorX`
11+
* and then sets it to the given value.
12+
*
13+
* The optional `step` property is applied incrementally, multiplied by each item in the array.
14+
*
15+
* To use this with a Group: `SetScrollFactorX(group.getChildren(), value, step)`
16+
*
17+
* @function Phaser.Actions.SetScrollFactorX
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} value - The amount to set the property to.
24+
* @param {number} [step=0] - This is added to the `value` amount, multiplied by the iteration counter.
25+
* @param {integer} [index=0] - An optional offset to start searching from within the items array.
26+
* @param {integer} [direction=1] - The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning.
27+
*
28+
* @return {(array|Phaser.GameObjects.GameObject[])} The array of objects that were passed to this Action.
29+
*/
30+
var SetScrollFactorX = function (items, value, step, index, direction)
31+
{
32+
return PropertyValueSet(items, 'scrollFactorX', value, step, index, direction);
33+
};
34+
35+
module.exports = SetScrollFactorX;

src/actions/SetScrollFactorY.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 property `scrollFactorY`
11+
* and then sets it to the given value.
12+
*
13+
* The optional `step` property is applied incrementally, multiplied by each item in the array.
14+
*
15+
* To use this with a Group: `SetScrollFactorY(group.getChildren(), value, step)`
16+
*
17+
* @function Phaser.Actions.SetScrollFactorY
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} value - The amount to set the property to.
24+
* @param {number} [step=0] - This is added to the `value` amount, multiplied by the iteration counter.
25+
* @param {integer} [index=0] - An optional offset to start searching from within the items array.
26+
* @param {integer} [direction=1] - The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning.
27+
*
28+
* @return {(array|Phaser.GameObjects.GameObject[])} The array of objects that were passed to this Action.
29+
*/
30+
var SetScrollFactorY = function (items, value, step, index, direction)
31+
{
32+
return PropertyValueSet(items, 'scrollFactorY', value, step, index, direction);
33+
};
34+
35+
module.exports = SetScrollFactorY;

src/actions/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ module.exports = {
4747
SetScale: require('./SetScale'),
4848
SetScaleX: require('./SetScaleX'),
4949
SetScaleY: require('./SetScaleY'),
50+
SetScrollFactor: require('./SetScrollFactor'),
51+
SetScrollFactorX: require('./SetScrollFactorX'),
52+
SetScrollFactorY: require('./SetScrollFactorY'),
5053
SetTint: require('./SetTint'),
5154
SetVisible: require('./SetVisible'),
5255
SetX: require('./SetX'),

src/gameobjects/group/Group.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,18 @@ var Group = new Class({
412412

413413
Actions.SetAlpha(entries, alpha, stepAlpha);
414414

415+
var depth = GetValue(options, 'setDepth.value', 0);
416+
var stepDepth = GetValue(options, 'setDepth.step', 0);
417+
418+
Actions.SetDepth(entries, depth, stepDepth);
419+
420+
var scrollFactorX = GetValue(options, 'setScrollFactor.x', 1);
421+
var scrollFactorY = GetValue(options, 'setScrollFactor.y', scrollFactorX);
422+
var stepScrollFactorX = GetValue(options, 'setScrollFactor.stepX', 0);
423+
var stepScrollFactorY = GetValue(options, 'setScrollFactor.stepY', 0);
424+
425+
Actions.SetScrollFactor(entries, scrollFactorX, scrollFactorY, stepScrollFactorX, stepScrollFactorY);
426+
415427
var hitArea = GetFastValue(options, 'hitArea', null);
416428
var hitAreaCallback = GetFastValue(options, 'hitAreaCallback', null);
417429

src/gameobjects/group/typedefs/GroupCreateConfig.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@
3838
* @property {?object} [setAlpha]
3939
* @property {?number} [setAlpha.value=0] - The alpha value of each new Game Object.
4040
* @property {?number} [setAlpha.step=0] - Increment each Game Object's alpha from the previous by this amount, starting from `setAlpha.value`.
41+
* @property {?object} [setDepth]
42+
* @property {?number} [setDepth.value=0] - The depth value of each new Game Object.
43+
* @property {?number} [setDepth.step=0] - Increment each Game Object's depth from the previous by this amount, starting from `setDepth.value`.
44+
* @property {?object} [setScrollFactor]
45+
* @property {?number} [setScrollFactor.x=0] - The horizontal scroll factor of each new Game Object.
46+
* @property {?number} [setScrollFactor.y=0] - The vertical scroll factor of each new Game Object.
47+
* @property {?number} [setScrollFactor.stepX=0] - Increment each Game Object's horizontal scroll factor from the previous by this amount, starting from `setScrollFactor.x`.
48+
* @property {?number} [setScrollFactor.stepY=0] - Increment each Game object's vertical scroll factor from the previous by this amount, starting from `setScrollFactor.y`.
4149
* @property {?*} [hitArea] - A geometric shape that defines the hit area for the Game Object.
4250
* @property {?Phaser.Types.Input.HitAreaCallback} [hitAreaCallback] - A callback to be invoked when the Game Object is interacted with.
4351
* @property {?(false|Phaser.Types.Actions.GridAlignConfig)} [gridAlign=false] - Align the new Game Objects in a grid using these settings.
@@ -48,6 +56,8 @@
4856
* @see Phaser.Actions.SetRotation
4957
* @see Phaser.Actions.SetScale
5058
* @see Phaser.Actions.SetXY
59+
* @see Phaser.Actions.SetDepth
60+
* @see Phaser.Actions.SetScrollFactor
5161
* @see Phaser.GameObjects.Group#createFromConfig
5262
* @see Phaser.Utils.Array.Range
5363
*/

0 commit comments

Comments
 (0)