-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
SetCenterX.js
29 lines (25 loc) · 903 Bytes
/
SetCenterX.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* @author Richard Davey <rich@phaser.io>
* @copyright 2013-2024 Phaser Studio Inc.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
/**
* Positions the Game Object so that the center top of its bounds aligns with the given coordinate.
*
* @function Phaser.Display.Bounds.SetCenterX
* @since 3.0.0
*
* @generic {Phaser.GameObjects.GameObject} G - [gameObject,$return]
*
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object that will be re-positioned.
* @param {number} x - The coordinate to position the Game Object bounds on.
*
* @return {Phaser.GameObjects.GameObject} The Game Object that was positioned.
*/
var SetCenterX = function (gameObject, x)
{
var offsetX = gameObject.width * gameObject.originX;
gameObject.x = (x + offsetX) - (gameObject.width * 0.5);
return gameObject;
};
module.exports = SetCenterX;