2015-03-01 07:00:17 +00:00
|
|
|
/**
|
2015-03-23 23:27:14 +00:00
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2016-04-04 21:15:01 +00:00
|
|
|
* @copyright 2016 Photon Storm Ltd.
|
2015-03-23 23:27:14 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Reset component allows a Game Object to be reset and repositioned to a new location.
|
2015-03-01 07:00:17 +00:00
|
|
|
*
|
|
|
|
* @class
|
|
|
|
*/
|
2015-02-17 05:15:04 +00:00
|
|
|
Phaser.Component.Reset = function () {};
|
|
|
|
|
|
|
|
/**
|
2015-03-23 23:27:14 +00:00
|
|
|
* Resets the Game Object.
|
|
|
|
*
|
|
|
|
* This moves the Game Object to the given x/y world coordinates and sets `fresh`, `exists`,
|
|
|
|
* `visible` and `renderable` to true.
|
|
|
|
*
|
|
|
|
* If this Game Object has the LifeSpan component it will also set `alive` to true and `health` to the given value.
|
|
|
|
*
|
|
|
|
* If this Game Object has a Physics Body it will reset the Body.
|
2015-02-17 05:15:04 +00:00
|
|
|
*
|
2015-03-01 07:00:17 +00:00
|
|
|
* @method
|
2015-03-23 23:27:14 +00:00
|
|
|
* @param {number} x - The x coordinate (in world space) to position the Game Object at.
|
|
|
|
* @param {number} y - The y coordinate (in world space) to position the Game Object at.
|
|
|
|
* @param {number} [health=1] - The health to give the Game Object if it has the Health component.
|
|
|
|
* @return {PIXI.DisplayObject} This instance.
|
2015-02-17 05:15:04 +00:00
|
|
|
*/
|
2015-03-24 21:35:09 +00:00
|
|
|
Phaser.Component.Reset.prototype.reset = function (x, y, health) {
|
2015-02-17 05:15:04 +00:00
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (health === undefined) { health = 1; }
|
2015-02-17 05:15:04 +00:00
|
|
|
|
|
|
|
this.world.set(x, y);
|
|
|
|
this.position.set(x, y);
|
|
|
|
|
|
|
|
this.fresh = true;
|
|
|
|
this.exists = true;
|
|
|
|
this.visible = true;
|
|
|
|
this.renderable = true;
|
|
|
|
|
|
|
|
if (this.components.InWorld)
|
|
|
|
{
|
|
|
|
this._outOfBoundsFired = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.components.LifeSpan)
|
|
|
|
{
|
|
|
|
this.alive = true;
|
|
|
|
this.health = health;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.components.PhysicsBody)
|
|
|
|
{
|
|
|
|
if (this.body)
|
|
|
|
{
|
|
|
|
this.body.reset(x, y, false, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
|
|
|
};
|