Particle Emitter in and working. Nice and fast, and a lot more flexible than before.

This commit is contained in:
Richard Davey
2013-09-10 01:26:50 +01:00
parent 2ba6b4ff67
commit 5d3fe891cd
11 changed files with 681 additions and 2 deletions
+36
View File
@@ -0,0 +1,36 @@
Phaser.RenderTexture = function (game, width, height) {
// If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all
this.exists = true;
// This is a handy little var your game can use to determine if a sprite is alive or not, it doesn't effect rendering
this.alive = true;
this.group = null;
this.name = '';
this.game = game;
PIXI.EventTarget.call( this );
this.width = width || 100;
this.height = height || 100;
this.indetityMatrix = PIXI.mat3.create();
this.frame = new PIXI.Rectangle(0, 0, this.width, this.height);
if (PIXI.gl)
{
this.initWebGL();
}
else
{
this.initCanvas();
}
};
Phaser.RenderTexture.prototype = Phaser.Utils.extend(true, PIXI.RenderTexture.prototype);
Phaser.RenderTexture.prototype.constructor = Phaser.RenderTexture;
+36
View File
@@ -19,6 +19,10 @@ Phaser.Sprite = function (game, x, y, key, frame) {
this.renderOrderID = -1;
// If you would like the Sprite to have a lifespan once 'born' you can set this to a positive value. Handy for particles, bullets, etc.
// The lifespan is decremented by game.time.elapsed each update, once it reaches zero the kill() function is called.
this.lifespan = 0;
if (key)
{
PIXI.Sprite.call(this, PIXI.TextureCache[key]);
@@ -164,6 +168,17 @@ Phaser.Sprite.prototype.update = function() {
return;
}
if (this.lifespan > 0)
{
this.lifespan -= this.game.time.elapsed;
if (this.lifespan <= 0)
{
this.kill();
return;
}
}
this._cache.dirty = false;
if (this.animations.update())
@@ -275,14 +290,35 @@ Phaser.Sprite.prototype.update = function() {
}
Phaser.Sprite.prototype.revive = function() {
this.alive = true;
this.exists = true;
this.visible = true;
this.events.onRevived.dispatch(this);
}
Phaser.Sprite.prototype.kill = function() {
this.alive = false;
this.exists = false;
this.visible = false;
this.events.onKilled.dispatch(this);
}
Phaser.Sprite.prototype.reset = function(x, y) {
this.x = x;
this.y = y;
this.position.x = x;
this.position.y = y;
this.alive = true;
this.exists = true;
this.visible = true;
this._outOfBoundsFired = false;
this.body.reset();
}