mirror of
https://github.com/wassname/phaser.git
synced 2026-07-26 13:27:43 +08:00
Adding docs.
This commit is contained in:
@@ -1,15 +1,47 @@
|
||||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
* @module Phaser.Particles
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Phaser.Particles constructor
|
||||
* @class Phaser.Particles
|
||||
* @classdesc Phaser Particles
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
Phaser.Particles = function (game) {
|
||||
|
||||
/**
|
||||
* @property {Description} emitters - Description.
|
||||
*/
|
||||
this.emitters = {};
|
||||
|
||||
/**
|
||||
* @property {number} ID - Description.
|
||||
* @default
|
||||
*/
|
||||
this.ID = 0;
|
||||
|
||||
};
|
||||
|
||||
Phaser.Particles.prototype = {
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method emitters
|
||||
*/
|
||||
emitters: null,
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method add
|
||||
* @param {Description} emitter - Description.
|
||||
* @return {Description} Description.
|
||||
*/
|
||||
add: function (emitter) {
|
||||
|
||||
this.emitters[emitter.name] = emitter;
|
||||
@@ -18,12 +50,22 @@ Phaser.Particles.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method remove
|
||||
* @param {Description} emitter - Description.
|
||||
*/
|
||||
remove: function (emitter) {
|
||||
|
||||
delete this.emitters[emitter.name];
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method update
|
||||
* @param {Description} emitter - Description.
|
||||
*/
|
||||
update: function () {
|
||||
|
||||
for (var key in this.emitters)
|
||||
|
||||
+163
-53
@@ -1,145 +1,210 @@
|
||||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
* @module Phaser.Emitter
|
||||
*/
|
||||
|
||||
/**
|
||||
* Phaser - ArcadeEmitter
|
||||
*
|
||||
* Emitter is a lightweight particle emitter. It can be used for one-time explosions or for
|
||||
* @class Phaser.Particles.Arcade.Emitter
|
||||
* @classdesc Emitter is a lightweight particle emitter. It can be used for one-time explosions or for
|
||||
* continuous effects like rain and fire. All it really does is launch Particle objects out
|
||||
* at set intervals, and fixes their positions and velocities accorindgly.
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - Current game instance.
|
||||
* @param {number} x - Description.
|
||||
* @param {number} y - Description.
|
||||
* @param {number} maxParticles - Description.
|
||||
*/
|
||||
|
||||
Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) {
|
||||
|
||||
/**
|
||||
* @property {number} maxParticles - Description.
|
||||
* @default
|
||||
*/
|
||||
maxParticles = maxParticles || 50;
|
||||
|
||||
Phaser.Group.call(this, game);
|
||||
|
||||
/**
|
||||
* @property {string} name - Description.
|
||||
*/
|
||||
this.name = 'emitter' + this.game.particles.ID++;
|
||||
|
||||
/**
|
||||
* @property {Description} type - Description.
|
||||
*/
|
||||
this.type = Phaser.EMITTER;
|
||||
|
||||
/**
|
||||
* The X position of the top left corner of the emitter in world space.
|
||||
* @property {number} x - The X position of the top left corner of the emitter in world space.
|
||||
* @default
|
||||
*/
|
||||
this.x = 0;
|
||||
|
||||
/**
|
||||
* The Y position of the top left corner of emitter in world space.
|
||||
* @property {number} y - The Y position of the top left corner of emitter in world space.
|
||||
* @default
|
||||
*/
|
||||
this.y = 0;
|
||||
|
||||
/**
|
||||
* The width of the emitter. Particles can be randomly generated from anywhere within this box.
|
||||
* @property {number} width - The width of the emitter. Particles can be randomly generated from anywhere within this box.
|
||||
* @default
|
||||
*/
|
||||
this.width = 1;
|
||||
|
||||
/**
|
||||
* The height of the emitter. Particles can be randomly generated from anywhere within this box.
|
||||
*/
|
||||
* @property {number} height - The height of the emitter. Particles can be randomly generated from anywhere within this box.
|
||||
* @default
|
||||
*/
|
||||
this.height = 1;
|
||||
|
||||
/**
|
||||
* The minimum possible velocity of a particle.
|
||||
* The default value is (-100,-100).
|
||||
*/
|
||||
* The minimum possible velocity of a particle.
|
||||
* The default value is (-100,-100).
|
||||
* @property {Phaser.Point} minParticleSpeed
|
||||
*/
|
||||
this.minParticleSpeed = new Phaser.Point(-100, -100);
|
||||
|
||||
/**
|
||||
* The maximum possible velocity of a particle.
|
||||
* The default value is (100,100).
|
||||
*/
|
||||
* The maximum possible velocity of a particle.
|
||||
* The default value is (100,100).
|
||||
* @property {Phaser.Point} maxParticleSpeed
|
||||
*/
|
||||
this.maxParticleSpeed = new Phaser.Point(100, 100);
|
||||
|
||||
/**
|
||||
* The minimum possible scale of a particle.
|
||||
* The default value is 1.
|
||||
*/
|
||||
* The minimum possible scale of a particle.
|
||||
* The default value is 1.
|
||||
* @property {number} minParticleScale
|
||||
* @default
|
||||
*/
|
||||
this.minParticleScale = 1;
|
||||
|
||||
/**
|
||||
* The maximum possible scale of a particle.
|
||||
* The default value is 1.
|
||||
* @property {number} maxParticleScale
|
||||
* @default
|
||||
*/
|
||||
this.maxParticleScale = 1;
|
||||
|
||||
/**
|
||||
* The minimum possible angular velocity of a particle. The default value is -360.
|
||||
* @property {number} minRotation
|
||||
* @default
|
||||
*/
|
||||
this.minRotation = -360;
|
||||
|
||||
/**
|
||||
* The maximum possible angular velocity of a particle. The default value is 360.
|
||||
* @property {number} maxRotation
|
||||
* @default
|
||||
*/
|
||||
this.maxRotation = 360;
|
||||
|
||||
/**
|
||||
* Sets the <code>gravity.y</code> of each particle to this value on launch.
|
||||
* @property {number} gravity
|
||||
* @default
|
||||
*/
|
||||
this.gravity = 2;
|
||||
|
||||
/**
|
||||
* Set your own particle class type here.
|
||||
* Default is <code>Particle</code>.
|
||||
* @property {Description} particleClass
|
||||
* @default
|
||||
*/
|
||||
this.particleClass = null;
|
||||
|
||||
/**
|
||||
* The X and Y drag component of particles launched from the emitter.
|
||||
* @property {Phaser.Point} particleDrag
|
||||
*/
|
||||
this.particleDrag = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* The angular drag component of particles launched from the emitter if they are rotating.
|
||||
* @property {number} angularDrag
|
||||
* @default
|
||||
*/
|
||||
this.angularDrag = 0;
|
||||
|
||||
/**
|
||||
* How often a particle is emitted in ms (if emitter is started with Explode == false).
|
||||
* @property {bool} frequency
|
||||
* @default
|
||||
*/
|
||||
this.frequency = 100;
|
||||
|
||||
/**
|
||||
* The total number of particles in this emitter.
|
||||
* @property {number} maxParticles
|
||||
*/
|
||||
this.maxParticles = maxParticles;
|
||||
|
||||
/**
|
||||
* How long each particle lives once it is emitted in ms. Default is 2 seconds.
|
||||
* Set lifespan to 'zero' for particles to live forever.
|
||||
* @property {number} lifespan
|
||||
* @default
|
||||
*/
|
||||
this.lifespan = 2000;
|
||||
|
||||
/**
|
||||
* How much each particle should bounce on each axis. 1 = full bounce, 0 = no bounce.
|
||||
* @property {Phaser.Point} bounce
|
||||
*/
|
||||
this.bounce = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* Internal helper for deciding how many particles to launch.
|
||||
* @property {number} _quantity
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._quantity = 0;
|
||||
|
||||
/**
|
||||
* Internal helper for deciding when to launch particles or kill them.
|
||||
* @property {number} _timer
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._timer = 0;
|
||||
|
||||
/**
|
||||
* Internal counter for figuring out how many particles to launch.
|
||||
* @property {number} _counter
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._counter = 0;
|
||||
|
||||
/**
|
||||
* Internal helper for the style of particle emission (all at once, or one at a time).
|
||||
* @property {bool} _explode
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._explode = true;
|
||||
|
||||
/**
|
||||
* Determines whether the emitter is currently emitting particles.
|
||||
* It is totally safe to directly toggle this.
|
||||
* @property {bool} on
|
||||
* @default
|
||||
*/
|
||||
this.on = false;
|
||||
|
||||
/**
|
||||
* Determines whether the emitter is being updated by the core game loop.
|
||||
* @property {bool} exists
|
||||
* @default
|
||||
*/
|
||||
this.exists = true;
|
||||
|
||||
@@ -147,8 +212,16 @@ Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) {
|
||||
* 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.
|
||||
* @property {bool} emitX
|
||||
*/
|
||||
this.emitX = x;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @property {bool} emitY
|
||||
*/
|
||||
this.emitY = y;
|
||||
|
||||
};
|
||||
@@ -158,6 +231,7 @@ Phaser.Particles.Arcade.Emitter.prototype.constructor = Phaser.Particles.Arcade.
|
||||
|
||||
/**
|
||||
* Called automatically by the game loop, decides when to launch particles and when to "die".
|
||||
* @method Phaser.Particles.Arcade.Emitter.prototype.update
|
||||
*/
|
||||
Phaser.Particles.Arcade.Emitter.prototype.update = function () {
|
||||
|
||||
@@ -202,12 +276,13 @@ Phaser.Particles.Arcade.Emitter.prototype.update = function () {
|
||||
/**
|
||||
* This function generates a new array of particle sprites to attach to the emitter.
|
||||
*
|
||||
* @param graphics If you opted to not pre-configure an array of Sprite objects, you can simply pass in a particle image or sprite sheet.
|
||||
* @param quantity {number} The number of particles to generate when using the "create from image" option.
|
||||
* @param multiple {boolean} Whether the image in the Graphics param is a single particle or a bunch of particles (if it's a bunch, they need to be square!).
|
||||
* @param collide {number} Whether the particles should be flagged as not 'dead' (non-colliding particles are higher performance). 0 means no collisions, 0-1 controls scale of particle's bounding box.
|
||||
*
|
||||
* @return This Emitter instance (nice for chaining stuff together, if you're into that).
|
||||
* @method Phaser.Particles.Arcade.Emitter.prototype.makeParticles
|
||||
* @param {Description} keys - Description.
|
||||
* @param {number} frames - Description.
|
||||
* @param {number} quantity - The number of particles to generate when using the "create from image" option.
|
||||
* @param {number} collide - Description.
|
||||
* @param {bool} collideWorldBounds - Description.
|
||||
* @return This Emitter instance (nice for chaining stuff together, if you're into that).
|
||||
*/
|
||||
Phaser.Particles.Arcade.Emitter.prototype.makeParticles = function (keys, frames, quantity, collide, collideWorldBounds) {
|
||||
|
||||
@@ -278,6 +353,7 @@ Phaser.Particles.Arcade.Emitter.prototype.makeParticles = function (keys, frames
|
||||
|
||||
/**
|
||||
* Call this function to turn off all the particles and the emitter.
|
||||
* @method Phaser.Particles.Arcade.Emitter.prototype.kill
|
||||
*/
|
||||
Phaser.Particles.Arcade.Emitter.prototype.kill = function () {
|
||||
|
||||
@@ -290,6 +366,7 @@ Phaser.Particles.Arcade.Emitter.prototype.kill = function () {
|
||||
/**
|
||||
* 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>.
|
||||
* @method Phaser.Particles.Arcade.Emitter.prototype.revive
|
||||
*/
|
||||
Phaser.Particles.Arcade.Emitter.prototype.revive = function () {
|
||||
|
||||
@@ -300,11 +377,11 @@ Phaser.Particles.Arcade.Emitter.prototype.revive = function () {
|
||||
|
||||
/**
|
||||
* Call this function to start emitting particles.
|
||||
*
|
||||
* @param explode {boolean} Whether the particles should all burst out at once.
|
||||
* @param lifespan {number} How long each particle lives once emitted. 0 = forever.
|
||||
* @param frequency {number} Ignored if Explode is set to true. Frequency is how often to emit a particle in ms.
|
||||
* @param quantity {number} How many particles to launch. 0 = "all of the particles".
|
||||
* @method Phaser.Particles.Arcade.Emitter.prototype.start
|
||||
* @param {boolean} explode - Whether the particles should all burst out at once.
|
||||
* @param {number} lifespan - How long each particle lives once emitted. 0 = forever.
|
||||
* @param {number} frequency - Ignored if Explode is set to true. Frequency is how often to emit a particle in ms.
|
||||
* @param {number} quantity - How many particles to launch. 0 = "all of the particles".
|
||||
*/
|
||||
Phaser.Particles.Arcade.Emitter.prototype.start = function (explode, lifespan, frequency, quantity) {
|
||||
|
||||
@@ -346,6 +423,7 @@ Phaser.Particles.Arcade.Emitter.prototype.start = function (explode, lifespan, f
|
||||
|
||||
/**
|
||||
* This function can be used both internally and externally to emit the next particle.
|
||||
* @method Phaser.Particles.Arcade.Emitter.prototype.emitParticle
|
||||
*/
|
||||
Phaser.Particles.Arcade.Emitter.prototype.emitParticle = function () {
|
||||
|
||||
@@ -412,9 +490,9 @@ Phaser.Particles.Arcade.Emitter.prototype.emitParticle = function () {
|
||||
|
||||
/**
|
||||
* A more compact way of setting the width and height of the emitter.
|
||||
*
|
||||
* @param width {number} The desired width of the emitter (particles are spawned randomly within these dimensions).
|
||||
* @param height {number} The desired height of the emitter.
|
||||
* @method Phaser.Particles.Arcade.Emitter.prototype.setSize
|
||||
* @param {number} width - The desired width of the emitter (particles are spawned randomly within these dimensions).
|
||||
* @param {number} height - The desired height of the emitter.
|
||||
*/
|
||||
Phaser.Particles.Arcade.Emitter.prototype.setSize = function (width, height) {
|
||||
|
||||
@@ -425,9 +503,9 @@ Phaser.Particles.Arcade.Emitter.prototype.setSize = function (width, height) {
|
||||
|
||||
/**
|
||||
* A more compact way of setting the X velocity range of the emitter.
|
||||
*
|
||||
* @param Min {number} The minimum value for this range.
|
||||
* @param Max {number} The maximum value for this range.
|
||||
* @method Phaser.Particles.Arcade.Emitter.prototype.setXSpeed
|
||||
* @param {number} min - The minimum value for this range.
|
||||
* @param {number} max - The maximum value for this range.
|
||||
*/
|
||||
Phaser.Particles.Arcade.Emitter.prototype.setXSpeed = function (min, max) {
|
||||
|
||||
@@ -441,9 +519,9 @@ Phaser.Particles.Arcade.Emitter.prototype.setXSpeed = function (min, max) {
|
||||
|
||||
/**
|
||||
* A more compact way of setting the Y velocity range of the emitter.
|
||||
*
|
||||
* @param Min {number} The minimum value for this range.
|
||||
* @param Max {number} The maximum value for this range.
|
||||
* @method Phaser.Particles.Arcade.Emitter.prototype.setYSpeed
|
||||
* @param {number} min - The minimum value for this range.
|
||||
* @param {number} max - The maximum value for this range.
|
||||
*/
|
||||
Phaser.Particles.Arcade.Emitter.prototype.setYSpeed = function (min, max) {
|
||||
|
||||
@@ -457,9 +535,9 @@ Phaser.Particles.Arcade.Emitter.prototype.setYSpeed = function (min, max) {
|
||||
|
||||
/**
|
||||
* A more compact way of setting the angular velocity constraints of the emitter.
|
||||
*
|
||||
* @param Min {number} The minimum value for this range.
|
||||
* @param Max {number} The maximum value for this range.
|
||||
* @method Phaser.Particles.Arcade.Emitter.prototype.setRotation
|
||||
* @param {number} min - The minimum value for this range.
|
||||
* @param {number} max - The maximum value for this range.
|
||||
*/
|
||||
Phaser.Particles.Arcade.Emitter.prototype.setRotation = function (min, max) {
|
||||
|
||||
@@ -473,8 +551,8 @@ Phaser.Particles.Arcade.Emitter.prototype.setRotation = function (min, max) {
|
||||
|
||||
/**
|
||||
* Change the emitter's midpoint to match the midpoint of a <code>Object</code>.
|
||||
*
|
||||
* @param Object {object} The <code>Object</code> that you want to sync up with.
|
||||
* @method Phaser.Particles.Arcade.Emitter.prototype.at
|
||||
* @param {object} object - The <code>Object</code> that you want to sync up with.
|
||||
*/
|
||||
Phaser.Particles.Arcade.Emitter.prototype.at = function (object) {
|
||||
|
||||
@@ -483,42 +561,51 @@ Phaser.Particles.Arcade.Emitter.prototype.at = function (object) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the emitter alpha.
|
||||
* @return {Description}
|
||||
*//**
|
||||
* Set the emiter alpha value.
|
||||
* @param {Description} value - Description
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Get the emitter visible state.
|
||||
* @return {bool}
|
||||
*//**
|
||||
* Set the emitter visible state.
|
||||
* @param {bool} value - Description
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Get
|
||||
* @return {bool}
|
||||
*//**
|
||||
* Set
|
||||
* @param {bool} value - Description
|
||||
*/
|
||||
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "x", {
|
||||
|
||||
get: function () {
|
||||
@@ -531,6 +618,13 @@ Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "x", {
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Get
|
||||
* @return {bool}
|
||||
*//**
|
||||
* Set
|
||||
* @param {bool} value - Description
|
||||
*/
|
||||
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "y", {
|
||||
|
||||
get: function () {
|
||||
@@ -543,6 +637,10 @@ Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "y", {
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Get
|
||||
* @return {number}
|
||||
*/
|
||||
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "left", {
|
||||
|
||||
get: function () {
|
||||
@@ -551,6 +649,10 @@ Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "left", {
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Get
|
||||
* @return {number}
|
||||
*/
|
||||
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "right", {
|
||||
|
||||
get: function () {
|
||||
@@ -559,6 +661,10 @@ Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "right", {
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Get
|
||||
* @return {number}
|
||||
*/
|
||||
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "top", {
|
||||
|
||||
get: function () {
|
||||
@@ -567,6 +673,10 @@ Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "top", {
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Get
|
||||
* @return {number}
|
||||
*/
|
||||
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "bottom", {
|
||||
|
||||
get: function () {
|
||||
|
||||
Reference in New Issue
Block a user