phaser/src/gameobjects/components/ScrollFactor.js

102 lines
4.2 KiB
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
2018-02-01 00:25:33 +00:00
/**
* Provides methods used for getting and setting the Scroll Factor of a Game Object.
2018-03-27 12:52:58 +00:00
*
2018-02-01 00:25:33 +00:00
* @name Phaser.GameObjects.Components.ScrollFactor
* @since 3.0.0
*/
2017-06-22 02:19:03 +00:00
var ScrollFactor = {
2017-06-26 12:17:31 +00:00
2018-02-01 00:25:33 +00:00
/**
* The horizontal scroll factor of this Game Object.
2018-03-27 12:52:58 +00:00
*
2018-02-01 00:25:33 +00:00
* The scroll factor controls the influence of the movement of a Camera upon this Game Object.
*
* When a camera scrolls it will change the location at which this Game Object is rendered on-screen.
* It does not change the Game Objects actual position values.
2018-03-27 12:52:58 +00:00
*
2018-02-01 00:25:33 +00:00
* A value of 1 means it will move exactly in sync with a camera.
* A value of 0 means it will not move at all, even if the camera moves.
* Other values control the degree to which the camera movement is mapped to this Game Object.
*
* Please be aware that scroll factor values other than 1 are not taken in to consideration when
* calculating physics collisions. Bodies always collide based on their world position, but changing
* the scroll factor is a visual adjustment to where the textures are rendered, which can offset
* them from physics bodies if not accounted for in your code.
2018-03-27 12:52:58 +00:00
*
2018-02-01 00:25:33 +00:00
* @name Phaser.GameObjects.Components.ScrollFactor#scrollFactorX
* @type {number}
* @default 1
* @since 3.0.0
*/
2018-01-04 15:21:02 +00:00
scrollFactorX: 1,
2018-02-01 00:25:33 +00:00
/**
* The vertical scroll factor of this Game Object.
2018-03-27 12:52:58 +00:00
*
2018-02-01 00:25:33 +00:00
* The scroll factor controls the influence of the movement of a Camera upon this Game Object.
*
* When a camera scrolls it will change the location at which this Game Object is rendered on-screen.
* It does not change the Game Objects actual position values.
2018-03-27 12:52:58 +00:00
*
2018-02-01 00:25:33 +00:00
* A value of 1 means it will move exactly in sync with a camera.
* A value of 0 means it will not move at all, even if the camera moves.
* Other values control the degree to which the camera movement is mapped to this Game Object.
*
* Please be aware that scroll factor values other than 1 are not taken in to consideration when
* calculating physics collisions. Bodies always collide based on their world position, but changing
* the scroll factor is a visual adjustment to where the textures are rendered, which can offset
* them from physics bodies if not accounted for in your code.
2018-03-27 12:52:58 +00:00
*
2018-02-01 00:25:33 +00:00
* @name Phaser.GameObjects.Components.ScrollFactor#scrollFactorY
* @type {number}
* @default 1
* @since 3.0.0
*/
2018-01-04 15:21:02 +00:00
scrollFactorY: 1,
2017-06-26 12:17:31 +00:00
2018-02-01 00:25:33 +00:00
/**
* Sets the scroll factor of this Game Object.
2018-03-27 12:52:58 +00:00
*
2018-02-01 00:25:33 +00:00
* The scroll factor controls the influence of the movement of a Camera upon this Game Object.
*
* When a camera scrolls it will change the location at which this Game Object is rendered on-screen.
* It does not change the Game Objects actual position values.
2018-03-27 12:52:58 +00:00
*
2018-02-01 00:25:33 +00:00
* A value of 1 means it will move exactly in sync with a camera.
* A value of 0 means it will not move at all, even if the camera moves.
* Other values control the degree to which the camera movement is mapped to this Game Object.
*
* Please be aware that scroll factor values other than 1 are not taken in to consideration when
* calculating physics collisions. Bodies always collide based on their world position, but changing
* the scroll factor is a visual adjustment to where the textures are rendered, which can offset
* them from physics bodies if not accounted for in your code.
2018-03-27 12:52:58 +00:00
*
2018-02-01 01:36:52 +00:00
* @method Phaser.GameObjects.Components.ScrollFactor#setScrollFactor
2018-02-01 00:25:33 +00:00
* @since 3.0.0
*
* @param {number} x - The horizontal scroll factor of this Game Object.
2018-03-27 12:52:58 +00:00
* @param {number} [y=x] - The vertical scroll factor of this Game Object. If not set it will use the `x` value.
*
2018-05-22 04:46:26 +00:00
* @return {this} This Game Object instance.
2018-02-01 00:25:33 +00:00
*/
2017-06-26 12:17:31 +00:00
setScrollFactor: function (x, y)
{
2017-06-26 14:07:53 +00:00
if (y === undefined) { y = x; }
2017-06-26 12:17:31 +00:00
this.scrollFactorX = x;
this.scrollFactorY = y;
return this;
}
2017-06-22 02:19:03 +00:00
};
module.exports = ScrollFactor;