2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2017-08-15 22:38:35 +00:00
|
|
|
var Class = require('../../utils/Class');
|
2017-08-15 23:30:12 +00:00
|
|
|
var ImpactBody = require('./ImpactBody');
|
2017-08-15 22:38:35 +00:00
|
|
|
var ImpactImage = require('./ImpactImage');
|
|
|
|
var ImpactSprite = require('./ImpactSprite');
|
|
|
|
|
2018-02-09 16:04:43 +00:00
|
|
|
/**
|
|
|
|
* @classdesc
|
|
|
|
* The Impact Physics Factory allows you to easily create Impact Physics enabled Game Objects.
|
|
|
|
* Objects that are created by this Factory are automatically added to the physics world.
|
|
|
|
*
|
|
|
|
* @class Factory
|
|
|
|
* @memberOf Phaser.Physics.Impact
|
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.Physics.Impact.World} world - [description]
|
|
|
|
*/
|
2017-08-15 22:38:35 +00:00
|
|
|
var Factory = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
function Factory (world)
|
|
|
|
{
|
2018-02-09 16:04:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Impact.Factory#world
|
|
|
|
* @type {Phaser.Physics.Impact.World}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-08-15 22:38:35 +00:00
|
|
|
this.world = world;
|
|
|
|
|
2018-02-09 16:04:43 +00:00
|
|
|
/**
|
|
|
|
* A reference to the Scene.Systems this Impact Physics instance belongs to.
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Impact.Factory#sys
|
|
|
|
* @type {Phaser.Scenes.Systems}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-08-15 22:38:35 +00:00
|
|
|
this.sys = world.scene.sys;
|
|
|
|
},
|
|
|
|
|
2018-02-09 16:04:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Impact.Factory#body
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {number} x - [description]
|
|
|
|
* @param {number} y - [description]
|
|
|
|
* @param {number} width - [description]
|
|
|
|
* @param {number} height - [description]
|
|
|
|
*
|
|
|
|
* @return {Phaser.Physics.Impact.ImpactBody} The ImpactBody object that was created.
|
|
|
|
*/
|
2017-08-15 23:30:12 +00:00
|
|
|
body: function (x, y, width, height)
|
2017-08-15 22:38:35 +00:00
|
|
|
{
|
2017-08-15 23:30:12 +00:00
|
|
|
return new ImpactBody(this.world, x, y, width, height);
|
2017-08-15 22:38:35 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 16:04:43 +00:00
|
|
|
/**
|
|
|
|
* Adds an Impact Physics Body to the given Game Object.
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Impact.Factory#existing
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.GameObjects.GameObject} gameObject - [description]
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.GameObject} The Game Object.
|
|
|
|
*/
|
2018-01-08 22:16:14 +00:00
|
|
|
existing: function (gameObject)
|
|
|
|
{
|
|
|
|
var x = gameObject.x - gameObject.frame.centerX;
|
|
|
|
var y = gameObject.y - gameObject.frame.centerY;
|
|
|
|
var w = gameObject.width;
|
|
|
|
var h = gameObject.height;
|
|
|
|
|
|
|
|
gameObject.body = this.world.create(x, y, w, h);
|
|
|
|
|
|
|
|
gameObject.body.parent = gameObject;
|
|
|
|
gameObject.body.gameObject = gameObject;
|
|
|
|
|
|
|
|
return gameObject;
|
|
|
|
},
|
|
|
|
|
2018-02-09 16:04:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Impact.Factory#image
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {number} x - The horizontal position of this Game Object in the world.
|
|
|
|
* @param {number} y - The vertical position of this Game Object in the world.
|
2018-03-18 23:42:09 +00:00
|
|
|
* @param {string} key - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager.
|
2018-03-20 15:10:19 +00:00
|
|
|
* @param {(string|integer)} [frame] - An optional frame from the Texture this Game Object is rendering with.
|
2018-02-09 16:04:43 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Physics.Impact.ImpactImage} The ImpactImage object that was created.
|
|
|
|
*/
|
2017-08-15 22:38:35 +00:00
|
|
|
image: function (x, y, key, frame)
|
|
|
|
{
|
|
|
|
var image = new ImpactImage(this.world, x, y, key, frame);
|
|
|
|
|
|
|
|
this.sys.displayList.add(image);
|
|
|
|
|
|
|
|
return image;
|
|
|
|
},
|
|
|
|
|
2018-02-09 16:04:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Impact.Factory#sprite
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {number} x - The horizontal position of this Game Object in the world.
|
|
|
|
* @param {number} y - The vertical position of this Game Object in the world.
|
2018-03-18 23:42:09 +00:00
|
|
|
* @param {string} key - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager.
|
2018-03-20 15:10:19 +00:00
|
|
|
* @param {(string|integer)} [frame] - An optional frame from the Texture this Game Object is rendering with.
|
2018-02-09 16:04:43 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Physics.Impact.ImpactSprite} The ImpactSprite object that was created.
|
|
|
|
*/
|
2017-08-15 22:38:35 +00:00
|
|
|
sprite: function (x, y, key, frame)
|
|
|
|
{
|
|
|
|
var sprite = new ImpactSprite(this.world, x, y, key, frame);
|
|
|
|
|
|
|
|
this.sys.displayList.add(sprite);
|
|
|
|
this.sys.updateList.add(sprite);
|
|
|
|
|
|
|
|
return sprite;
|
2018-04-13 16:12:17 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys this Factory.
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Impact.Factory#destroy
|
|
|
|
* @since 3.4.1
|
|
|
|
*/
|
|
|
|
destroy: function ()
|
|
|
|
{
|
|
|
|
this.world = null;
|
|
|
|
this.sys = null;
|
2017-08-15 22:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Factory;
|