2013-04-18 13:16:18 +00:00
|
|
|
/// <reference path="../Game.ts" />
|
|
|
|
/// <reference path="Sprite.ts" />
|
|
|
|
|
|
|
|
/**
|
2013-04-18 15:49:08 +00:00
|
|
|
* Phaser - Particle
|
|
|
|
*
|
|
|
|
* This is a simple particle class that extends a Sprite to have a slightly more
|
|
|
|
* specialised behaviour. It is used exclusively by the Emitter class and can be extended as required.
|
2013-04-18 13:16:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
module Phaser {
|
|
|
|
|
|
|
|
export class Particle extends Sprite {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiate a new particle. Like <code>Sprite</code>, all meaningful creation
|
|
|
|
* happens during <code>loadGraphic()</code> or <code>makeGraphic()</code> or whatever.
|
|
|
|
*/
|
|
|
|
constructor(game: Game) {
|
|
|
|
|
|
|
|
super(game);
|
|
|
|
|
2013-05-31 18:28:16 +00:00
|
|
|
this.body.type = Types.BODY_DYNAMIC;
|
2013-04-18 13:16:18 +00:00
|
|
|
this.lifespan = 0;
|
2013-04-28 13:59:44 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* How long this particle lives before it disappears.
|
|
|
|
* NOTE: this is a maximum, not a minimum; the object
|
|
|
|
* could get recycled before its lifespan is up.
|
|
|
|
*/
|
|
|
|
public lifespan: number;
|
|
|
|
|
|
|
|
/**
|
2013-06-26 04:44:56 +00:00
|
|
|
* The particle's main update logic. Basically it checks to see if it should be dead yet.
|
2013-04-18 13:16:18 +00:00
|
|
|
*/
|
|
|
|
public update() {
|
2013-04-28 11:25:02 +00:00
|
|
|
|
2013-05-31 18:28:16 +00:00
|
|
|
// Lifespan behavior
|
2013-04-18 13:16:18 +00:00
|
|
|
if (this.lifespan <= 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-31 17:21:32 +00:00
|
|
|
this.lifespan -= this.game.time.elapsed;
|
2013-04-18 13:16:18 +00:00
|
|
|
|
|
|
|
if (this.lifespan <= 0)
|
|
|
|
{
|
|
|
|
this.kill();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Triggered whenever this object is launched by a <code>Emitter</code>.
|
|
|
|
* You can override this to add custom behavior like a sound or AI or something.
|
|
|
|
*/
|
|
|
|
public onEmit() {
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|