phaser/src/gameobjects/components/ScrollFactor.js
2018-03-27 14:52:58 +02:00

86 lines
3.1 KiB
JavaScript

/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* Provides methods used for getting and setting the Scroll Factor of a Game Object.
*
* @name Phaser.GameObjects.Components.ScrollFactor
* @since 3.0.0
*/
var ScrollFactor = {
/**
* The horizontal scroll factor of this Game Object.
*
* 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.
*
* 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.
*
* @name Phaser.GameObjects.Components.ScrollFactor#scrollFactorX
* @type {number}
* @default 1
* @since 3.0.0
*/
scrollFactorX: 1,
/**
* The vertical scroll factor of this Game Object.
*
* 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.
*
* 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.
*
* @name Phaser.GameObjects.Components.ScrollFactor#scrollFactorY
* @type {number}
* @default 1
* @since 3.0.0
*/
scrollFactorY: 1,
/**
* Sets the scroll factor of this Game Object.
*
* 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.
*
* 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.
*
* @method Phaser.GameObjects.Components.ScrollFactor#setScrollFactor
* @since 3.0.0
*
* @param {number} x - The horizontal scroll factor of this Game Object.
* @param {number} [y=x] - The vertical scroll factor of this Game Object. If not set it will use the `x` value.
*
* @return {Phaser.GameObjects.GameObject} This Game Object instance.
*/
setScrollFactor: function (x, y)
{
if (y === undefined) { y = x; }
this.scrollFactorX = x;
this.scrollFactorY = y;
return this;
}
};
module.exports = ScrollFactor;