Fixed a fantastic FrameData bug. Also added support to the Emitter to handle multiple image keys and/or frames.

This commit is contained in:
Richard Davey
2013-09-10 11:09:25 +01:00
parent 5d3fe891cd
commit 4f950ae801
10 changed files with 703 additions and 281 deletions
+39 -1
View File
@@ -1 +1,39 @@
Phaser.Particles = {}
Phaser.Particles = function (game) {
this.emitters = {};
this.ID = 0;
};
Phaser.Particles.prototype = {
emitters: null,
add: function (emitter) {
this.emitters[emitter.name] = emitter;
return emitter;
},
remove: function (emitter) {
delete this.emitters[emitter.name];
},
update: function () {
for (var key in this.emitters)
{
if (this.emitters[key].exists)
{
this.emitters[key].update();
}
}
},
};
+67 -25
View File
@@ -12,6 +12,8 @@ Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) {
Phaser.Group.call(this, game);
this.name = 'emitter' + this.game.particles.ID++;
/**
* The X position of the top left corner of the emitter in world space.
*/
@@ -119,12 +121,16 @@ Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) {
*/
this.on = false;
/**
* Determines whether the emitter is being updated by the core game loop.
*/
this.exists = true;
this.active = true;
// Needs to be a setter/getter and toggle the _container property
this.visible = true;
// The point the particles are emitted from (Emitter.x/y control the container location, i.e. all particles, this controls position within it)
/**
* The point the particles are emitted from.
* Emitter.x and Emitter.y control the containers location, which updates all current particles
* Emitter.emitX and Emitter.emitY control the emission location relative to the x/y position.
*/
this.emitX = 0;
this.emitY = 0;
@@ -186,42 +192,42 @@ Phaser.Particles.Arcade.Emitter.prototype.update = function () {
*
* @return This Emitter instance (nice for chaining stuff together, if you're into that).
*/
Phaser.Particles.Arcade.Emitter.prototype.makeParticles = function (key, quantity, multiple, collide) {
Phaser.Particles.Arcade.Emitter.prototype.makeParticles = function (keys, frames, quantity, collide) {
if (typeof frames == 'undefined')
{
frames = 0;
}
quantity = quantity || this.maxParticles;
multiple = multiple || false;
collide = collide || 0;
var totalFrames = 1;
var randomFrame;
var particle;
var i = 0;
var rndKey = keys;
var rndFrame = 0;
while (i < quantity)
{
if (this.particleClass == null)
{
particle = new Phaser.Sprite(this.game, 0, 0, key);
if (typeof keys == 'object')
{
rndKey = this.game.rnd.pick(keys);
}
if (typeof frames == 'object')
{
rndFrame = this.game.rnd.pick(frames);
}
particle = new Phaser.Sprite(this.game, 0, 0, rndKey, rndFrame);
}
else
{
// particle = new this.particleClass(this.game);
}
if (multiple)
{
/*
randomFrame = this.game.math.random()*totalFrames;
*/
}
else
{
// if (graphics)
// {
// particle.texture.loadImage(graphics);
// }
}
if (collide > 0)
{
particle.body.allowCollision.any = true;
@@ -433,11 +439,47 @@ Phaser.Particles.Arcade.Emitter.prototype.setRotation = function (min, max) {
*/
Phaser.Particles.Arcade.Emitter.prototype.at = function (object) {
//this.x = object.body.bounds.halfWidth - (this.width >> 1);
//this.y = object.body.bounds.halfHeight - (this.height >> 1);
this.emitX = object.center.x;
this.emitY = object.center.y;
}
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "alpha", {
/**
* Get the emitter alpha.
*/
get: function () {
return this._container.alpha;
},
/**
* Set the emiter alpha value.
*/
set: function (value) {
this._container.alpha = value;
}
});
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "visible", {
/**
* Get the emitter visible state.
*/
get: function () {
return this._container.visible;
},
/**
* Set the emitter visible state.
*/
set: function (value) {
this._container.visible = value;
}
});
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "left", {
get: function () {