2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2019-01-15 16:20:22 +00:00
|
|
|
* @copyright 2019 Photon Storm Ltd.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2018-02-12 16:01:20 +00:00
|
|
|
*/
|
|
|
|
|
2018-02-09 01:40:41 +00:00
|
|
|
/**
|
2018-09-28 11:19:21 +00:00
|
|
|
* The Impact Body Scale component.
|
|
|
|
* Should be applied as a mixin.
|
2018-02-09 01:40:41 +00:00
|
|
|
*
|
2019-02-12 15:01:54 +00:00
|
|
|
* @namespace Phaser.Physics.Impact.Components.BodyScale
|
2018-02-09 01:40:41 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-08-17 05:00:38 +00:00
|
|
|
var BodyScale = {
|
|
|
|
|
2018-02-09 01:40:41 +00:00
|
|
|
/**
|
2018-09-28 11:19:21 +00:00
|
|
|
* Sets the size of the physics body.
|
2018-02-09 01:40:41 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Impact.Components.BodyScale#setBodySize
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-09-28 11:19:21 +00:00
|
|
|
* @param {number} width - The width of the body in pixels.
|
|
|
|
* @param {number} [height=width] - The height of the body in pixels.
|
2018-02-09 01:40:41 +00:00
|
|
|
*
|
2018-09-28 11:19:21 +00:00
|
|
|
* @return {this} This Game Object.
|
2018-02-09 01:40:41 +00:00
|
|
|
*/
|
2017-08-17 05:00:38 +00:00
|
|
|
setBodySize: function (width, height)
|
|
|
|
{
|
|
|
|
if (height === undefined) { height = width; }
|
|
|
|
|
|
|
|
this.body.size.x = Math.round(width);
|
|
|
|
this.body.size.y = Math.round(height);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 01:40:41 +00:00
|
|
|
/**
|
2018-09-28 11:19:21 +00:00
|
|
|
* Sets the scale of the physics body.
|
2018-02-09 01:40:41 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Impact.Components.BodyScale#setBodyScale
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-09-28 11:19:21 +00:00
|
|
|
* @param {number} scaleX - The horizontal scale of the body.
|
|
|
|
* @param {number} [scaleY] - The vertical scale of the body. If not given, will use the horizontal scale value.
|
2018-02-09 01:40:41 +00:00
|
|
|
*
|
2018-09-28 11:19:21 +00:00
|
|
|
* @return {this} This Game Object.
|
2018-02-09 01:40:41 +00:00
|
|
|
*/
|
2017-08-17 05:00:38 +00:00
|
|
|
setBodyScale: function (scaleX, scaleY)
|
|
|
|
{
|
|
|
|
if (scaleY === undefined) { scaleY = scaleX; }
|
|
|
|
|
|
|
|
var gameObject = this.body.gameObject;
|
|
|
|
|
|
|
|
if (gameObject)
|
|
|
|
{
|
|
|
|
gameObject.setScale(scaleX, scaleY);
|
|
|
|
|
|
|
|
return this.setBodySize(gameObject.width * gameObject.scaleX, gameObject.height * gameObject.scaleY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this.setBodySize(this.body.size.x * scaleX, this.body.size.y * scaleY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = BodyScale;
|