2013-08-08 18:16:47 +00:00
|
|
|
/// <reference path="../_definitions.ts" />
|
2013-04-18 13:16:18 +00:00
|
|
|
|
|
|
|
/**
|
2013-04-18 15:49:08 +00:00
|
|
|
* Phaser - Sprite
|
2013-04-18 13:16:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
module Phaser {
|
|
|
|
|
2013-05-29 01:58:56 +00:00
|
|
|
export class Sprite implements IGameObject {
|
2013-04-18 13:16:18 +00:00
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
|
|
|
* Create a new <code>Sprite</code>.
|
|
|
|
*
|
|
|
|
* @param game {Phaser.Game} Current game instance.
|
2013-05-04 16:18:45 +00:00
|
|
|
* @param [x] {number} the initial x position of the sprite.
|
|
|
|
* @param [y] {number} the initial y position of the sprite.
|
|
|
|
* @param [key] {string} Key of the graphic you want to load for this sprite.
|
2013-05-04 12:02:12 +00:00
|
|
|
*/
|
2013-08-08 10:34:33 +00:00
|
|
|
constructor(game: Game, x: number = 0, y: number = 0, key: string = null, frame = null) {
|
2013-04-18 13:16:18 +00:00
|
|
|
|
2013-05-28 20:38:37 +00:00
|
|
|
this.game = game;
|
|
|
|
this.type = Phaser.Types.SPRITE;
|
2013-04-18 13:16:18 +00:00
|
|
|
|
2013-05-28 20:38:37 +00:00
|
|
|
this.exists = true;
|
|
|
|
this.active = true;
|
|
|
|
this.visible = true;
|
|
|
|
this.alive = true;
|
2013-04-18 13:16:18 +00:00
|
|
|
|
2013-05-29 11:24:25 +00:00
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
2013-06-02 02:47:54 +00:00
|
|
|
this.z = -1;
|
|
|
|
this.group = null;
|
2013-07-02 22:41:25 +00:00
|
|
|
this.name = '';
|
2013-05-29 11:24:25 +00:00
|
|
|
|
2013-08-06 02:14:48 +00:00
|
|
|
this.events = new Phaser.Components.Events(this);
|
2013-06-06 01:47:08 +00:00
|
|
|
this.animations = new Phaser.Components.AnimationManager(this);
|
2013-08-06 02:14:48 +00:00
|
|
|
this.input = new Phaser.Components.InputHandler(this);
|
|
|
|
this.texture = new Phaser.Display.Texture(this);
|
|
|
|
this.transform = new Phaser.Components.TransformManager(this);
|
2013-06-01 00:30:36 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
if (key !== null)
|
|
|
|
{
|
|
|
|
this.texture.loadImage(key, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.texture.opaque = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frame !== null)
|
|
|
|
{
|
|
|
|
if (typeof frame == 'string')
|
|
|
|
{
|
|
|
|
this.frameName = frame;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.frame = frame;
|
|
|
|
}
|
|
|
|
}
|
2013-06-01 01:49:41 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
this.worldView = new Rectangle(x, y, this.width, this.height);
|
2013-06-07 18:18:39 +00:00
|
|
|
this.cameraView = new Rectangle(x, y, this.width, this.height);
|
2013-04-18 13:16:18 +00:00
|
|
|
|
2013-06-11 20:30:15 +00:00
|
|
|
this.transform.setCache();
|
|
|
|
|
2013-07-13 11:38:59 +00:00
|
|
|
this.outOfBounds = false;
|
2013-07-15 20:45:26 +00:00
|
|
|
this.outOfBoundsAction = Phaser.Types.OUT_OF_BOUNDS_PERSIST;
|
2013-07-13 11:38:59 +00:00
|
|
|
|
2013-06-13 00:55:32 +00:00
|
|
|
// Handy proxies
|
|
|
|
this.scale = this.transform.scale;
|
|
|
|
this.alpha = this.texture.alpha;
|
|
|
|
this.origin = this.transform.origin;
|
2013-08-01 21:21:03 +00:00
|
|
|
this.crop = this.texture.crop;
|
2013-06-13 00:55:32 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
2013-05-28 20:38:37 +00:00
|
|
|
* Reference to the main game object
|
2013-05-04 12:02:12 +00:00
|
|
|
*/
|
2013-08-08 18:16:47 +00:00
|
|
|
public game: Phaser.Game;
|
2013-05-16 01:36:58 +00:00
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
2013-05-28 20:38:37 +00:00
|
|
|
* The type of game object.
|
2013-05-04 12:02:12 +00:00
|
|
|
*/
|
2013-05-28 20:38:37 +00:00
|
|
|
public type: number;
|
2013-04-19 17:53:21 +00:00
|
|
|
|
2013-07-02 22:41:25 +00:00
|
|
|
/**
|
|
|
|
* The name of game object.
|
|
|
|
*/
|
|
|
|
public name: string;
|
|
|
|
|
2013-06-02 02:47:54 +00:00
|
|
|
/**
|
|
|
|
* The Group this Sprite belongs to.
|
|
|
|
*/
|
2013-08-08 18:16:47 +00:00
|
|
|
public group: Phaser.Group;
|
2013-06-02 02:47:54 +00:00
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
2013-05-28 20:38:37 +00:00
|
|
|
* Controls if both <code>update</code> and render are called by the core game loop.
|
2013-05-04 12:02:12 +00:00
|
|
|
*/
|
2013-08-08 10:34:33 +00:00
|
|
|
public exists: boolean;
|
2013-05-16 01:36:58 +00:00
|
|
|
|
|
|
|
/**
|
2013-05-28 20:38:37 +00:00
|
|
|
* Controls if <code>update()</code> is automatically called by the core game loop.
|
2013-05-16 01:36:58 +00:00
|
|
|
*/
|
2013-08-08 10:34:33 +00:00
|
|
|
public active: boolean;
|
2013-05-16 01:36:58 +00:00
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
2013-05-28 20:38:37 +00:00
|
|
|
* Controls if this Sprite is rendered or skipped during the core game loop.
|
2013-05-04 12:02:12 +00:00
|
|
|
*/
|
2013-08-08 10:34:33 +00:00
|
|
|
public visible: boolean;
|
2013-05-16 01:36:58 +00:00
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
2013-06-06 01:47:08 +00:00
|
|
|
* A useful state for many game objects. Kill and revive both flip this switch.
|
2013-05-04 12:02:12 +00:00
|
|
|
*/
|
2013-08-08 10:34:33 +00:00
|
|
|
public alive: boolean;
|
2013-05-16 01:36:58 +00:00
|
|
|
|
2013-07-13 11:38:59 +00:00
|
|
|
/**
|
|
|
|
* Is the Sprite out of the world bounds or not?
|
|
|
|
*/
|
2013-08-08 10:34:33 +00:00
|
|
|
public outOfBounds: boolean;
|
2013-07-13 11:38:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The action to be taken when the sprite is fully out of the world bounds
|
2013-08-02 17:32:26 +00:00
|
|
|
* Defaults to Phaser.Types.OUT_OF_BOUNDS_PERSIST
|
2013-07-13 11:38:59 +00:00
|
|
|
*/
|
|
|
|
public outOfBoundsAction: number;
|
|
|
|
|
2013-05-29 20:39:08 +00:00
|
|
|
/**
|
2013-05-31 14:13:03 +00:00
|
|
|
* Sprite physics body.
|
2013-05-29 20:39:08 +00:00
|
|
|
*/
|
2013-08-08 18:16:47 +00:00
|
|
|
//public body: Phaser.Physics.Body = null;
|
|
|
|
public body;
|
2013-05-29 20:39:08 +00:00
|
|
|
|
2013-05-04 12:02:12 +00:00
|
|
|
/**
|
2013-05-28 20:38:37 +00:00
|
|
|
* The texture used to render the Sprite.
|
2013-05-04 12:02:12 +00:00
|
|
|
*/
|
2013-08-06 02:14:48 +00:00
|
|
|
public texture: Phaser.Display.Texture;
|
2013-04-18 13:16:18 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
/**
|
|
|
|
* The Sprite transform component.
|
|
|
|
*/
|
2013-08-06 02:14:48 +00:00
|
|
|
public transform: Phaser.Components.TransformManager;
|
2013-06-06 01:47:08 +00:00
|
|
|
|
2013-06-01 01:49:41 +00:00
|
|
|
/**
|
|
|
|
* The Input component
|
|
|
|
*/
|
2013-08-06 02:14:48 +00:00
|
|
|
public input: Phaser.Components.InputHandler;
|
2013-06-01 01:49:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Events component
|
|
|
|
*/
|
2013-08-06 02:14:48 +00:00
|
|
|
public events: Phaser.Components.Events;
|
2013-06-01 01:49:41 +00:00
|
|
|
|
2013-05-29 14:45:34 +00:00
|
|
|
/**
|
2013-08-06 02:14:48 +00:00
|
|
|
* This manages animations of the sprite. You can modify animations through it. (see AnimationManager)
|
2013-05-29 14:45:34 +00:00
|
|
|
* @type AnimationManager
|
|
|
|
*/
|
|
|
|
public animations: Phaser.Components.AnimationManager;
|
|
|
|
|
2013-05-31 17:21:32 +00:00
|
|
|
/**
|
2013-06-06 01:47:08 +00:00
|
|
|
* A Rectangle that defines the size and placement of the Sprite in the game world,
|
|
|
|
* after taking into consideration both scrollFactor and scaling.
|
2013-05-29 14:45:34 +00:00
|
|
|
*/
|
2013-06-06 01:47:08 +00:00
|
|
|
public worldView: Phaser.Rectangle;
|
2013-05-29 14:45:34 +00:00
|
|
|
|
2013-06-07 18:18:39 +00:00
|
|
|
/**
|
|
|
|
* A Rectangle that maps to the placement of this sprite with respect to a specific Camera.
|
|
|
|
* This value is constantly updated and modified during the internal render pass, it is not meant to be accessed directly.
|
|
|
|
*/
|
|
|
|
public cameraView: Phaser.Rectangle;
|
|
|
|
|
2013-07-13 11:38:59 +00:00
|
|
|
/**
|
|
|
|
* A local tween variable. Used by the TweenManager when setting a tween on this sprite or a property of it.
|
|
|
|
*/
|
|
|
|
public tween: Phaser.Tween;
|
|
|
|
|
2013-05-29 14:45:34 +00:00
|
|
|
/**
|
|
|
|
* A boolean representing if the Sprite has been modified in any way via a scale, rotate, flip or skew.
|
|
|
|
*/
|
2013-08-08 10:34:33 +00:00
|
|
|
public modified: boolean = false;
|
2013-05-29 14:45:34 +00:00
|
|
|
|
2013-05-29 11:24:25 +00:00
|
|
|
/**
|
|
|
|
* x value of the object.
|
|
|
|
*/
|
|
|
|
public x: number = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* y value of the object.
|
|
|
|
*/
|
|
|
|
public y: number = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* z order value of the object.
|
|
|
|
*/
|
2013-07-02 22:41:25 +00:00
|
|
|
public z: number = -1;
|
2013-05-29 11:24:25 +00:00
|
|
|
|
2013-06-03 11:03:34 +00:00
|
|
|
/**
|
2013-06-06 01:47:08 +00:00
|
|
|
* Render iteration counter
|
2013-06-03 11:03:34 +00:00
|
|
|
*/
|
|
|
|
public renderOrderID: number = 0;
|
|
|
|
|
2013-05-29 11:24:25 +00:00
|
|
|
/**
|
2013-06-06 01:47:08 +00:00
|
|
|
* The rotation of the sprite in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
|
2013-05-29 11:24:25 +00:00
|
|
|
*/
|
2013-06-06 01:47:08 +00:00
|
|
|
public get rotation(): number {
|
|
|
|
return this.transform.rotation;
|
2013-05-29 11:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-06-06 01:47:08 +00:00
|
|
|
* Set the rotation of the sprite in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
|
2013-05-29 11:24:25 +00:00
|
|
|
* The value is automatically wrapped to be between 0 and 360.
|
|
|
|
*/
|
2013-06-06 01:47:08 +00:00
|
|
|
public set rotation(value: number) {
|
2013-07-02 22:41:25 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
this.transform.rotation = this.game.math.wrap(value, 360, 0);
|
2013-07-02 22:41:25 +00:00
|
|
|
|
|
|
|
if (this.body)
|
|
|
|
{
|
2013-08-02 11:38:56 +00:00
|
|
|
//this.body.angle = this.game.math.degreesToRadians(this.game.math.wrap(value, 360, 0));
|
2013-07-02 22:41:25 +00:00
|
|
|
}
|
|
|
|
|
2013-05-29 11:24:25 +00:00
|
|
|
}
|
|
|
|
|
2013-07-28 23:43:10 +00:00
|
|
|
/**
|
|
|
|
* Brings this Sprite to the top of its current Group, if set.
|
|
|
|
*/
|
|
|
|
public bringToTop() {
|
|
|
|
|
|
|
|
if (this.group)
|
|
|
|
{
|
2013-08-08 18:16:47 +00:00
|
|
|
//this.group.bringToTop(this);
|
2013-07-28 23:43:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-13 00:55:32 +00:00
|
|
|
/**
|
|
|
|
* The scale of the Sprite. A value of 1 is original scale. 0.5 is half size. 2 is double the size.
|
|
|
|
* This is a reference to Sprite.transform.scale
|
|
|
|
*/
|
|
|
|
public scale: Phaser.Vec2;
|
|
|
|
|
2013-08-01 21:21:03 +00:00
|
|
|
/**
|
|
|
|
* The crop rectangle allows you to control which part of the sprite texture is rendered without distorting it.
|
|
|
|
* Set to null to disable, set to a Phaser.Rectangle object to control the region that will be rendered, anything outside the rectangle is ignored.
|
2013-08-06 23:00:12 +00:00
|
|
|
* This is a reference to Sprite.texture.crop
|
2013-08-01 21:21:03 +00:00
|
|
|
* @type {Phaser.Rectangle}
|
|
|
|
*/
|
|
|
|
public crop: Phaser.Rectangle;
|
|
|
|
|
2013-07-12 02:28:46 +00:00
|
|
|
/**
|
|
|
|
* The origin of the Sprite around which rotation and positioning takes place.
|
|
|
|
* This is a reference to Sprite.transform.origin
|
|
|
|
*/
|
|
|
|
public origin: Phaser.Vec2;
|
|
|
|
|
2013-06-13 00:55:32 +00:00
|
|
|
/**
|
|
|
|
* The alpha of the Sprite between 0 and 1, a value of 1 being fully opaque.
|
|
|
|
*/
|
2013-07-12 02:28:46 +00:00
|
|
|
public set alpha(value: number) {
|
|
|
|
this.texture.alpha = value;
|
|
|
|
}
|
2013-06-13 00:55:32 +00:00
|
|
|
|
|
|
|
/**
|
2013-07-12 02:28:46 +00:00
|
|
|
* The alpha of the Sprite between 0 and 1, a value of 1 being fully opaque.
|
2013-06-13 00:55:32 +00:00
|
|
|
*/
|
2013-07-12 02:28:46 +00:00
|
|
|
public get alpha(): number {
|
|
|
|
return this.texture.alpha;
|
|
|
|
}
|
2013-06-13 00:55:32 +00:00
|
|
|
|
2013-05-29 14:45:34 +00:00
|
|
|
/**
|
|
|
|
* Set the animation frame by frame number.
|
|
|
|
*/
|
|
|
|
public set frame(value: number) {
|
|
|
|
this.animations.frame = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the animation frame number.
|
|
|
|
*/
|
|
|
|
public get frame(): number {
|
|
|
|
return this.animations.frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the animation frame by frame name.
|
|
|
|
*/
|
|
|
|
public set frameName(value: string) {
|
|
|
|
this.animations.frameName = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the animation frame name.
|
|
|
|
*/
|
|
|
|
public get frameName(): string {
|
|
|
|
return this.animations.frameName;
|
|
|
|
}
|
|
|
|
|
2013-05-30 04:34:35 +00:00
|
|
|
public set width(value: number) {
|
2013-06-06 01:47:08 +00:00
|
|
|
this.transform.scale.x = value / this.texture.width;
|
2013-05-30 04:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public get width(): number {
|
2013-06-06 01:47:08 +00:00
|
|
|
return this.texture.width * this.transform.scale.x;
|
2013-05-30 04:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public set height(value: number) {
|
2013-06-06 01:47:08 +00:00
|
|
|
this.transform.scale.y = value / this.texture.height;
|
2013-05-30 04:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public get height(): number {
|
2013-06-06 01:47:08 +00:00
|
|
|
return this.texture.height * this.transform.scale.y;
|
2013-05-30 04:34:35 +00:00
|
|
|
}
|
|
|
|
|
2013-05-29 01:58:56 +00:00
|
|
|
/**
|
|
|
|
* Pre-update is called right before update() on each object in the game loop.
|
|
|
|
*/
|
|
|
|
public preUpdate() {
|
|
|
|
|
2013-06-07 15:27:33 +00:00
|
|
|
this.transform.update();
|
|
|
|
|
2013-08-06 03:34:52 +00:00
|
|
|
if (this.transform.scrollFactor.x != 1 && this.transform.scrollFactor.x != 0)
|
|
|
|
{
|
|
|
|
this.worldView.x = (this.x * this.transform.scrollFactor.x) - (this.width * this.transform.origin.x);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.worldView.x = this.x - (this.width * this.transform.origin.x);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.transform.scrollFactor.y != 1 && this.transform.scrollFactor.y != 0)
|
|
|
|
{
|
|
|
|
this.worldView.y = (this.y * this.transform.scrollFactor.y) - (this.height * this.transform.origin.y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.worldView.y = this.y - (this.height * this.transform.origin.y);
|
|
|
|
}
|
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
this.worldView.width = this.width;
|
|
|
|
this.worldView.height = this.height;
|
2013-06-03 02:08:24 +00:00
|
|
|
|
2013-06-06 01:47:08 +00:00
|
|
|
if (this.modified == false && (!this.transform.scale.equals(1) || !this.transform.skew.equals(0) || this.transform.rotation != 0 || this.transform.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY))
|
2013-05-29 14:45:34 +00:00
|
|
|
{
|
|
|
|
this.modified = true;
|
|
|
|
}
|
|
|
|
|
2013-05-29 01:58:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-06-26 04:44:56 +00:00
|
|
|
* Override this function to update your sprites position and appearance.
|
2013-05-29 01:58:56 +00:00
|
|
|
*/
|
|
|
|
public update() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-07-13 11:38:59 +00:00
|
|
|
* Automatically called after update() by the game loop for all 'alive' objects.
|
2013-05-29 01:58:56 +00:00
|
|
|
*/
|
|
|
|
public postUpdate() {
|
|
|
|
|
|
|
|
this.animations.update();
|
|
|
|
|
2013-08-06 02:14:48 +00:00
|
|
|
this.checkBounds();
|
|
|
|
|
|
|
|
if (this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false)
|
|
|
|
{
|
|
|
|
this.modified = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private checkBounds() {
|
|
|
|
|
2013-07-13 11:38:59 +00:00
|
|
|
if (Phaser.RectangleUtils.intersects(this.worldView, this.game.world.bounds))
|
2013-05-29 01:58:56 +00:00
|
|
|
{
|
2013-07-13 11:38:59 +00:00
|
|
|
this.outOfBounds = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (this.outOfBounds == false)
|
2013-05-29 01:58:56 +00:00
|
|
|
{
|
2013-07-13 11:38:59 +00:00
|
|
|
this.events.onOutOfBounds.dispatch(this);
|
2013-05-29 01:58:56 +00:00
|
|
|
}
|
2013-07-13 11:38:59 +00:00
|
|
|
|
|
|
|
this.outOfBounds = true;
|
|
|
|
|
|
|
|
if (this.outOfBoundsAction == Phaser.Types.OUT_OF_BOUNDS_KILL)
|
|
|
|
{
|
|
|
|
this.kill();
|
|
|
|
}
|
|
|
|
else if (this.outOfBoundsAction == Phaser.Types.OUT_OF_BOUNDS_DESTROY)
|
2013-05-29 01:58:56 +00:00
|
|
|
{
|
2013-07-13 11:38:59 +00:00
|
|
|
this.destroy();
|
2013-05-29 01:58:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clean up memory.
|
|
|
|
*/
|
|
|
|
public destroy() {
|
2013-06-03 11:03:34 +00:00
|
|
|
|
2013-06-13 00:55:32 +00:00
|
|
|
this.input.destroy();
|
2013-06-02 02:47:54 +00:00
|
|
|
|
2013-05-29 01:58:56 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 17:21:32 +00:00
|
|
|
/**
|
|
|
|
* Handy for "killing" game objects.
|
|
|
|
* Default behavior is to flag them as nonexistent AND dead.
|
|
|
|
* However, if you want the "corpse" to remain in the game,
|
|
|
|
* like to animate an effect or whatever, you should override this,
|
|
|
|
* setting only alive to false, and leaving exists true.
|
|
|
|
*/
|
2013-08-08 10:34:33 +00:00
|
|
|
public kill(removeFromGroup:boolean = false) {
|
2013-06-02 02:47:54 +00:00
|
|
|
|
2013-05-31 17:21:32 +00:00
|
|
|
this.alive = false;
|
|
|
|
this.exists = false;
|
2013-06-02 02:47:54 +00:00
|
|
|
|
|
|
|
if (removeFromGroup && this.group)
|
|
|
|
{
|
2013-08-08 18:16:47 +00:00
|
|
|
//this.group.remove(this);
|
2013-06-02 02:47:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.events.onKilled.dispatch(this);
|
|
|
|
|
2013-05-31 17:21:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handy for bringing game objects "back to life". Just sets alive and exists back to true.
|
|
|
|
* In practice, this is most often called by <code>Object.reset()</code>.
|
|
|
|
*/
|
|
|
|
public revive() {
|
2013-06-02 02:47:54 +00:00
|
|
|
|
2013-05-31 17:21:32 +00:00
|
|
|
this.alive = true;
|
|
|
|
this.exists = true;
|
2013-06-02 02:47:54 +00:00
|
|
|
|
|
|
|
this.events.onRevived.dispatch(this);
|
|
|
|
|
2013-05-31 17:21:32 +00:00
|
|
|
}
|
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|