Skip to content

Commit

Permalink
PluginManager parent parameter removed as it's redundant. Also most c…
Browse files Browse the repository at this point in the history
…ore functions tidied up and jsdocs fixed.
  • Loading branch information
photonstorm committed Apr 9, 2014
1 parent 50981fd commit be52515
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 85 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Updated
* Grunt update to dev dependencies (thanks @xtian, #695)
* Emitter now emits Phaser.Particle objects instead of Phaser.Sprites, which can be extended as required.
* Emitter has had various local properties removed that were already declared in Phaser.Group which it extends.
* PluginManager parent parameter removed as it's redundant. Also most core functions tidied up and jsdocs fixed.


New Features
Expand All @@ -105,6 +106,9 @@ New Features
* Key.enabled boolean allows you to toggle if a Key processes its update method or dispatches any events without deleting and re-creating it.
* Emitter now has minParticleAlpha and maxParticleAlpha values for setting a random alpha on emitted particles.
* Emitter.particleAnchor allows you to control the anchor of emitted Particles. Defaults to 0.5 (same as before) but now under your control.
* Emitter.setAlpha allows you to quickly set the min and max alpha values.
* Emitter.setScale allows you to quickly set the min and max scale values.
* Emitter.blendMode lets you set the blendMode of any emitted Particle (needs a browser that supports canvas blend modes)


Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion src/core/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ Phaser.Game.prototype = {
this.sound = new Phaser.SoundManager(this);
this.physics = new Phaser.Physics(this, this.physicsConfig);
this.particles = new Phaser.Particles(this);
this.plugins = new Phaser.PluginManager(this, this);
this.plugins = new Phaser.PluginManager(this);
this.net = new Phaser.Net(this);
this.debug = new Phaser.Utils.Debug(this);

Expand Down
126 changes: 58 additions & 68 deletions src/core/PluginManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,42 @@
* @classdesc Phaser - PluginManager
* @constructor
* @param {Phaser.Game} game - A reference to the currently running game.
* @param {Description} parent - Description.
*/
Phaser.PluginManager = function(game, parent) {
Phaser.PluginManager = function(game) {

/**
* @property {Phaser.Game} game - A reference to the currently running game.
*/
this.game = game;

/**
* @property {Description} _parent - Description.
* @private
* @property {array} plugins - An array of all the plugins being managed by this PluginManager.
*/
this._parent = parent;
this.plugins = [];

/**
* @property {array} plugins - Description.
* @property {number} _len - Internal cache var.
* @private
*/
this.plugins = [];
this._len = 0;

/**
* @property {array} _pluginsLength - Description.
* @property {number} _i - Internal cache var.
* @private
* @default
*/
this._pluginsLength = 0;
this._i = 0;

};

Phaser.PluginManager.prototype = {

/**
* Add a new Plugin to the PluginManager.
* The plugin's game and parent reference are set to this game and pluginmanager parent.
* Add a new Plugin into the PluginManager.
* The Plugin must have 2 properties: game and parent. Plugin.game is set to ths game reference the PluginManager uses, and parent is set to the PluginManager.
*
* @method Phaser.PluginManager#add
* @param {Phaser.Plugin} plugin - Description.
* @return {Phaser.Plugin} Description.
* @param {object|Phaser.Plugin} plugin - The Plugin to add into the PluginManager. This can be a function or an existing object.
* @return {Phaser.Plugin} The Plugin that was added to the manager.
*/
add: function (plugin) {

Expand All @@ -63,7 +62,7 @@ Phaser.PluginManager.prototype = {
else
{
plugin.game = this.game;
plugin.parent = this._parent;
plugin.parent = this;
}

// Check for methods now to avoid having to do this every loop
Expand Down Expand Up @@ -110,7 +109,7 @@ Phaser.PluginManager.prototype = {
plugin.visible = true;
}

this._pluginsLength = this.plugins.push(plugin);
this._len = this.plugins.push(plugin);

// Allows plugins to run potentially destructive code outside of the constructor, and only if being added to the PluginManager
if (typeof plugin['init'] === 'function')
Expand All @@ -127,41 +126,48 @@ Phaser.PluginManager.prototype = {
},

/**
* Remove a Plugin from the PluginManager.
* Remove a Plugin from the PluginManager. It calls Plugin.destroy on the plugin before removing it from the manager.
*
* @method Phaser.PluginManager#remove
* @param {Phaser.Plugin} plugin - The plugin to be removed.
*/
remove: function (plugin) {

if (this._pluginsLength === 0)
{
return;
}
this._i = this._len;

for (this._p = 0; this._p < this._pluginsLength; this._p++)
while (this._i--)
{
if (this.plugins[this._p] === plugin)
if (this.plugins[this._i] === plugin)
{
plugin.destroy();
this.plugins.splice(this._p, 1);
this._pluginsLength--;
this.plugins.splice(this._i, 1);
this._len--;
return;
}
}

},

/**
* Removes all Plugins from the PluginManager.
* Remove all Plugins from the PluginManager. It calls Plugin.destroy on every plugin before removing it from the manager.
*
* @method Phaser.PluginManager#removeAll
*/
removeAll: function() {

for (this._p = 0; this._p < this._pluginsLength; this._p++)
this._i = this._len;

while (this._i--)
{
this.plugins[this._p].destroy();
if (this.plugins[this._i] === plugin)
{
plugin.destroy();
}
}

this.plugins.length = 0;
this._pluginsLength = 0;
this._len = 0;

},

/**
Expand All @@ -172,16 +178,13 @@ Phaser.PluginManager.prototype = {
*/
preUpdate: function () {

if (this._pluginsLength === 0)
{
return;
}
this._i = this._len;

for (this._p = 0; this._p < this._pluginsLength; this._p++)
while (this._i--)
{
if (this.plugins[this._p].active && this.plugins[this._p].hasPreUpdate)
if (this.plugins[this._i].active && this.plugins[this._i].hasPreUpdate)
{
this.plugins[this._p].preUpdate();
this.plugins[this._i].preUpdate();
}
}

Expand All @@ -195,16 +198,13 @@ Phaser.PluginManager.prototype = {
*/
update: function () {

if (this._pluginsLength === 0)
{
return;
}
this._i = this._len;

for (this._p = 0; this._p < this._pluginsLength; this._p++)
while (this._i--)
{
if (this.plugins[this._p].active && this.plugins[this._p].hasUpdate)
if (this.plugins[this._i].active && this.plugins[this._i].hasUpdate)
{
this.plugins[this._p].update();
this.plugins[this._i].update();
}
}

Expand All @@ -219,16 +219,13 @@ Phaser.PluginManager.prototype = {
*/
postUpdate: function () {

if (this._pluginsLength === 0)
{
return;
}
this._i = this._len;

for (this._p = 0; this._p < this._pluginsLength; this._p++)
while (this._i--)
{
if (this.plugins[this._p].active && this.plugins[this._p].hasPostUpdate)
if (this.plugins[this._i].active && this.plugins[this._i].hasPostUpdate)
{
this.plugins[this._p].postUpdate();
this.plugins[this._i].postUpdate();
}
}

Expand All @@ -242,16 +239,13 @@ Phaser.PluginManager.prototype = {
*/
render: function () {

if (this._pluginsLength === 0)
{
return;
}
this._i = this._len;

for (this._p = 0; this._p < this._pluginsLength; this._p++)
while (this._i--)
{
if (this.plugins[this._p].visible && this.plugins[this._p].hasRender)
if (this.plugins[this._i].visible && this.plugins[this._i].hasRender)
{
this.plugins[this._p].render();
this.plugins[this._i].render();
}
}

Expand All @@ -265,32 +259,28 @@ Phaser.PluginManager.prototype = {
*/
postRender: function () {

if (this._pluginsLength === 0)
{
return;
}
this._i = this._len;

for (this._p = 0; this._p < this._pluginsLength; this._p++)
while (this._i--)
{
if (this.plugins[this._p].visible && this.plugins[this._p].hasPostRender)
if (this.plugins[this._i].visible && this.plugins[this._i].hasPostRender)
{
this.plugins[this._p].postRender();
this.plugins[this._i].postRender();
}
}

},

/**
* Clear down this PluginManager and null out references
* Clear down this PluginManager, calls destroy on every plugin and nulls out references.
*
* @method Phaser.PluginManager#destroy
*/
destroy: function () {

this.plugins.length = 0;
this._pluginsLength = 0;
this.removeAll();

this.game = null;
this._parent = null;

}

Expand Down
40 changes: 24 additions & 16 deletions src/particles/arcade/Emitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,6 @@ Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) {
*/
this.type = Phaser.EMITTER;

/**
* @property {number} x - The X position of the top left corner of the emitter in world space.
* @default
*/
// this.x = 0;

/**
* @property {number} y - The Y position of the top left corner of emitter in world space.
* @default
*/
// this.y = 0;

/**
* @property {number} width - The width of the emitter. Particles can be randomly generated from anywhere within this box.
* @default
Expand Down Expand Up @@ -165,10 +153,10 @@ Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) {
this.particleAnchor = new Phaser.Point(0.5, 0.5);

/**
* @property {boolean} exists - Determines whether the emitter is being updated by the core game loop.
* @property {number} blendMode - The blendMode as set on the particle when emitted from the Emitter. Defaults to NORMAL. Needs browser capable of supporting canvas blend-modes (most not available in WebGL)
* @default
*/
// this.exists = true;
this.blendMode = Phaser.blendModes.NORMAL;

/**
* The point the particles are emitted from.
Expand Down Expand Up @@ -479,6 +467,8 @@ Phaser.Particles.Arcade.Emitter.prototype.emitParticle = function () {
particle.alpha = this.game.rnd.realInRange(this.minParticleAlpha, this.maxParticleAlpha);
}

particle.blendMode = this.blendMode;

particle.body.gravity.y = this.gravity;
particle.body.drag.x = this.particleDrag.x;
particle.body.drag.y = this.particleDrag.y;
Expand Down Expand Up @@ -532,7 +522,8 @@ Phaser.Particles.Arcade.Emitter.prototype.setYSpeed = function (min, max) {
};

/**
* A more compact way of setting the angular velocity constraints of the emitter.
* A more compact way of setting the angular velocity constraints of the particles.
*
* @method Phaser.Particles.Arcade.Emitter#setRotation
* @param {number} [min=0] - The minimum value for this range.
* @param {number} [max=0] - The maximum value for this range.
Expand All @@ -548,7 +539,7 @@ Phaser.Particles.Arcade.Emitter.prototype.setRotation = function (min, max) {
};

/**
* A more compact way of setting the alpha constraints of the emitter.
* A more compact way of setting the alpha constraints of the particles.
*
* @method Phaser.Particles.Arcade.Emitter#setAlpha
* @param {number} [min=1] - The minimum value for this range.
Expand All @@ -564,6 +555,23 @@ Phaser.Particles.Arcade.Emitter.prototype.setAlpha = function (min, max) {

};

/**
* A more compact way of setting the scale constraints of the particles.
*
* @method Phaser.Particles.Arcade.Emitter#setScale
* @param {number} [min=1] - The minimum value for this range.
* @param {number} [max=1] - The maximum value for this range.
*/
Phaser.Particles.Arcade.Emitter.prototype.setScale = function (min, max) {

if (typeof min === 'undefined') { min = 1; }
if (typeof max === 'undefined') { max = 1; }

this.minParticleScale = min;
this.maxParticleScale = max;

};

/**
* Change the emitters center to match the center of any object with a `center` property, such as a Sprite.
* If the object doesn't have a center property it will be set to object.x + object.width / 2
Expand Down

0 comments on commit be52515

Please sign in to comment.