phaser/src/physics/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>
2019-01-15 16:20:22 +00:00
* @copyright 2019 Photon Storm Ltd.
2018-02-12 16:01:20 +00:00
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
2018-09-28 12:19:21 +01: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-19 00:42:09 +01:00
* @param {Phaser.GameObjects.GameObject} gameObject - [description]
* @param {boolean} [sync=true] - [description]
*
2018-03-19 00:42:09 +01: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-19 00:42:09 +01: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;