mirror of
https://github.com/photonstorm/phaser
synced 2024-12-01 00:49:41 +00:00
4de95c09b5
- Required changes for documentation to show up correctly - Uses multiple @extends, which currently [mostly] works in jsdoc and like closure compiler
52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
/**
|
|
* Reset Component Features.
|
|
*
|
|
* @class
|
|
*/
|
|
Phaser.Component.Reset = function () {};
|
|
|
|
/**
|
|
* Resets the Sprite. This places the Sprite at the given x/y world coordinates and then
|
|
* sets alive, exists, visible and renderable all to true. Also resets the outOfBounds state and health values.
|
|
* If the Sprite has a physics body that too is reset.
|
|
*
|
|
* @method
|
|
* @param {number} x - The x coordinate (in world space) to position the Sprite at.
|
|
* @param {number} y - The y coordinate (in world space) to position the Sprite at.
|
|
* @param {number} [health=1] - The health to give the Sprite. Only applies if the GameObject has the Health component.
|
|
* @return (Phaser.Sprite) This instance.
|
|
*/
|
|
Phaser.Component.Reset.prototype.reset = function(x, y, health) {
|
|
|
|
if (typeof health === 'undefined') { health = 1; }
|
|
|
|
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;
|
|
|
|
};
|