phaser/plugins/impact/components/SetGameObject.js

71 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2020-01-15 12:07:09 +00:00
* @copyright 2020 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-09-28 11:19:21 +00:00
* The Impact Set Game Object component.
* Should be applied as a mixin.
*
* @namespace Phaser.Physics.Impact.Components.SetGameObject
* @since 3.0.0
*/
var SetGameObject = {
/**
* [description]
*
* @method Phaser.Physics.Impact.Components.SetGameObject#setGameObject
* @since 3.0.0
*
2018-03-18 23:42:09 +00:00
* @param {Phaser.GameObjects.GameObject} gameObject - [description]
* @param {boolean} [sync=true] - [description]
*
2018-03-18 23:42:09 +00:00
* @return {Phaser.GameObjects.GameObject} This Game Object.
*/
setGameObject: function (gameObject, sync)
{
if (sync === undefined) { sync = true; }
if (gameObject)
{
this.body.gameObject = gameObject;
if (sync)
{
this.syncGameObject();
}
}
else
{
this.body.gameObject = null;
}
return this;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.Components.SetGameObject#syncGameObject
* @since 3.0.0
*
2018-03-18 23:42:09 +00:00
* @return {Phaser.GameObjects.GameObject} This Game Object.
*/
syncGameObject: function ()
{
var gameObject = this.body.gameObject;
if (gameObject)
{
this.setBodySize(gameObject.width * gameObject.scaleX, gameObject.height * gameObject.scaleY);
}
return this;
}
};
module.exports = SetGameObject;