2013-10-02 19:18:24 +00:00
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "utf-8" >
< title > Phaser Source: particles/arcade/Emitter.js< / title >
<!-- [if lt IE 9]>
< script src = "//html5shiv.googlecode.com/svn/trunk/html5.js" > < / script >
<![endif]-->
< link type = "text/css" rel = "stylesheet" href = "styles/sunlight.default.css" >
< link type = "text/css" rel = "stylesheet" href = "styles/site.cerulean.css" >
< / head >
< body >
< div class = "container-fluid" >
< div class = "navbar navbar-fixed-top navbar-inverse" >
< div class = "navbar-inner" >
< a class = "brand" href = "index.html" > Phaser< / a >
< ul class = "nav" >
< li class = "dropdown" >
2013-10-03 01:38:35 +00:00
< a href = "namespaces.list.html" class = "dropdown-toggle" data-toggle = "dropdown" > Namespaces< b
2013-10-02 19:18:24 +00:00
class="caret">< / b > < / a >
< ul class = "dropdown-menu " >
< li >
2013-10-03 01:38:35 +00:00
< a href = "Phaser.html" > Phaser< / a >
2013-10-02 19:18:24 +00:00
< / li >
< / ul >
< / li >
< li class = "dropdown" >
< a href = "classes.list.html" class = "dropdown-toggle" data-toggle = "dropdown" > Classes< b
class="caret">< / b > < / a >
< ul class = "dropdown-menu " >
< li >
< a href = "Phaser.Animation.html" > Animation< / a >
< / li >
< li >
2013-10-03 01:38:35 +00:00
< a href = "Phaser.AnimationManager.html" > AnimationManager< / a >
2013-10-02 19:18:24 +00:00
< / li >
< li >
2013-10-03 01:38:35 +00:00
< a href = "Phaser.AnimationParser.html" > AnimationParser< / a >
2013-10-02 19:18:24 +00:00
< / li >
2013-11-28 15:57:09 +00:00
< li >
< a href = "Phaser.BitmapData.html" > BitmapData< / a >
< / li >
2014-02-18 03:01:51 +00:00
< li >
< a href = "Phaser.BitmapFont.html" > BitmapFont< / a >
< / li >
2013-10-25 15:54:40 +00:00
< li >
< a href = "Phaser.BitmapText.html" > BitmapText< / a >
< / li >
< li >
< a href = "Phaser.Button.html" > Button< / a >
< / li >
2013-10-02 19:18:24 +00:00
< li >
2013-10-03 01:38:35 +00:00
< a href = "Phaser.Cache.html" > Cache< / a >
2013-10-02 19:18:24 +00:00
< / li >
< li >
2013-10-03 01:38:35 +00:00
< a href = "Phaser.Camera.html" > Camera< / a >
2013-10-02 19:18:24 +00:00
< / li >
< li >
2013-10-03 01:38:35 +00:00
< a href = "Phaser.Canvas.html" > Canvas< / a >
2013-10-02 19:18:24 +00:00
< / li >
< li >
2013-10-03 01:38:35 +00:00
< a href = "Phaser.Circle.html" > Circle< / a >
2013-10-02 19:18:24 +00:00
< / li >
2013-10-03 00:21:08 +00:00
< li >
2013-10-03 01:38:35 +00:00
< a href = "Phaser.Color.html" > Color< / a >
2013-10-03 00:21:08 +00:00
< / li >
2013-10-02 19:18:24 +00:00
< li >
2013-10-03 01:38:35 +00:00
< a href = "Phaser.Device.html" > Device< / a >
2013-10-02 19:18:24 +00:00
< / li >
2013-10-03 00:21:08 +00:00
< li >
2013-10-03 01:38:35 +00:00
< a href = "Phaser.Easing.html" > Easing< / a >
< / li >
< li >
< a href = "Phaser.Easing.Back.html" > Back< / a >
< / li >
< li >
< a href = "Phaser.Easing.Bounce.html" > Bounce< / a >
< / li >
< li >
< a href = "Phaser.Easing.Circular.html" > Circular< / a >
< / li >
< li >
< a href = "Phaser.Easing.Cubic.html" > Cubic< / a >
< / li >
< li >
< a href = "Phaser.Easing.Elastic.html" > Elastic< / a >
< / li >
< li >
< a href = "Phaser.Easing.Exponential.html" > Exponential< / a >
< / li >
< li >
< a href = "Phaser.Easing.Linear.html" > Linear< / a >
< / li >
< li >
< a href = "Phaser.Easing.Quadratic.html" > Quadratic< / a >
< / li >
< li >
< a href = "Phaser.Easing.Quartic.html" > Quartic< / a >
< / li >
< li >
< a href = "Phaser.Easing.Quintic.html" > Quintic< / a >
< / li >
< li >
< a href = "Phaser.Easing.Sinusoidal.html" > Sinusoidal< / a >
< / li >
2014-02-18 03:01:51 +00:00
< li >
< a href = "Phaser.Ellipse.html" > Ellipse< / a >
< / li >
2013-10-25 15:54:40 +00:00
< li >
< a href = "Phaser.Events.html" > Events< / a >
< / li >
2013-11-28 15:57:09 +00:00
< li >
< a href = "Phaser.Filter.html" > Filter< / a >
< / li >
2013-10-03 01:38:35 +00:00
< li >
< a href = "Phaser.Frame.html" > Frame< / a >
< / li >
< li >
< a href = "Phaser.FrameData.html" > FrameData< / a >
2013-10-03 00:21:08 +00:00
< / li >
2013-10-02 19:18:24 +00:00
< li >
< a href = "Phaser.Game.html" > Game< / a >
< / li >
2014-02-21 15:37:26 +00:00
< li >
< a href = "Phaser.GameObjectCreator.html" > GameObjectCreator< / a >
< / li >
2013-10-25 15:54:40 +00:00
< li >
< a href = "Phaser.GameObjectFactory.html" > GameObjectFactory< / a >
< / li >
2014-02-05 06:29:17 +00:00
< li >
< a href = "Phaser.Gamepad.html" > Gamepad< / a >
< / li >
< li >
< a href = "Phaser.GamepadButton.html" > GamepadButton< / a >
< / li >
2013-10-25 15:54:40 +00:00
< li >
< a href = "Phaser.Graphics.html" > Graphics< / a >
< / li >
2013-10-02 19:18:24 +00:00
< li >
< a href = "Phaser.Group.html" > Group< / a >
< / li >
2014-02-08 07:24:22 +00:00
< li >
< a href = "Phaser.Image.html" > Image< / a >
< / li >
2013-10-02 19:18:24 +00:00
< li >
< a href = "Phaser.Input.html" > Input< / a >
< / li >
< li >
< a href = "Phaser.InputHandler.html" > InputHandler< / a >
< / li >
< li >
< a href = "Phaser.Key.html" > Key< / a >
< / li >
< li >
< a href = "Phaser.Keyboard.html" > Keyboard< / a >
< / li >
2014-02-05 06:29:17 +00:00
< li >
< a href = "Phaser.Line.html" > Line< / a >
< / li >
2013-10-02 19:18:24 +00:00
< li >
< a href = "Phaser.LinkedList.html" > LinkedList< / a >
< / li >
< li >
< a href = "Phaser.Loader.html" > Loader< / a >
< / li >
< li >
2013-10-03 01:38:35 +00:00
< a href = "Phaser.LoaderParser.html" > LoaderParser< / a >
2013-10-02 19:18:24 +00:00
< / li >
< li >
< a href = "Phaser.Math.html" > Math< / a >
< / li >
< li >
< a href = "Phaser.Mouse.html" > Mouse< / a >
< / li >
< li >
< a href = "Phaser.MSPointer.html" > MSPointer< / a >
< / li >
< li >
< a href = "Phaser.Net.html" > Net< / a >
< / li >
< li >
< a href = "Phaser.Particles.html" > Particles< / a >
< / li >
< li >
< a href = "Phaser.Particles.Arcade.Emitter.html" > Emitter< / a >
< / li >
2013-10-25 15:54:40 +00:00
< li >
< a href = "Phaser.Physics.html" > Physics< / a >
< / li >
< li >
< a href = "Phaser.Physics.Arcade.html" > Arcade< / a >
< / li >
2014-02-21 15:37:26 +00:00
< li >
< a href = "Phaser.Physics.Body.html" > Body< / a >
< / li >
< li >
< a href = "Phaser.Physics.CollisionGroup.html" > CollisionGroup< / a >
< / li >
< li >
< a href = "Phaser.Physics.ContactMaterial.html" > ContactMaterial< / a >
< / li >
< li >
< a href = "Phaser.Physics.InversePointProxy.html" > InversePointProxy< / a >
< / li >
< li >
< a href = "Phaser.Physics.Material.html" > Material< / a >
< / li >
< li >
< a href = "Phaser.Physics.PointProxy.html" > PointProxy< / a >
< / li >
< li >
< a href = "Phaser.Physics.Spring.html" > Spring< / a >
< / li >
< li >
< a href = "Phaser.Physics.World.html" > World< / a >
< / li >
2013-10-02 19:18:24 +00:00
< li >
< a href = "Phaser.Plugin.html" > Plugin< / a >
< / li >
< li >
< a href = "Phaser.PluginManager.html" > PluginManager< / a >
< / li >
< li >
< a href = "Phaser.Point.html" > Point< / a >
< / li >
< li >
< a href = "Phaser.Pointer.html" > Pointer< / a >
< / li >
2013-11-07 06:10:15 +00:00
< li >
< a href = "Phaser.Polygon.html" > Polygon< / a >
< / li >
2013-10-02 19:18:24 +00:00
< li >
< a href = "Phaser.RandomDataGenerator.html" > RandomDataGenerator< / a >
< / li >
< li >
< a href = "Phaser.Rectangle.html" > Rectangle< / a >
< / li >
2013-10-25 15:54:40 +00:00
< li >
< a href = "Phaser.RenderTexture.html" > RenderTexture< / a >
< / li >
2013-10-03 00:21:08 +00:00
< li >
< a href = "Phaser.RequestAnimationFrame.html" > RequestAnimationFrame< / a >
< / li >
2013-10-02 19:18:24 +00:00
< li >
< a href = "Phaser.Signal.html" > Signal< / a >
< / li >
2014-02-05 06:29:17 +00:00
< li >
< a href = "Phaser.SinglePad.html" > SinglePad< / a >
< / li >
2013-10-03 00:21:08 +00:00
< li >
< a href = "Phaser.Sound.html" > Sound< / a >
< / li >
< li >
< a href = "Phaser.SoundManager.html" > SoundManager< / a >
< / li >
2013-10-25 15:54:40 +00:00
< li >
< a href = "Phaser.Sprite.html" > Sprite< / a >
< / li >
2014-02-18 03:01:51 +00:00
< li >
< a href = "Phaser.SpriteBatch.html" > SpriteBatch< / a >
< / li >
2013-10-02 19:18:24 +00:00
< li >
< a href = "Phaser.Stage.html" > Stage< / a >
< / li >
2013-10-03 00:21:08 +00:00
< li >
< a href = "Phaser.StageScaleMode.html" > StageScaleMode< / a >
< / li >
2013-10-02 19:18:24 +00:00
< li >
< a href = "Phaser.State.html" > State< / a >
< / li >
< li >
< a href = "Phaser.StateManager.html" > StateManager< / a >
< / li >
2013-10-25 15:54:40 +00:00
< li >
< a href = "Phaser.Text.html" > Text< / a >
< / li >
2013-11-28 15:57:09 +00:00
< li >
< a href = "Phaser.Tile.html" > Tile< / a >
< / li >
< li >
< a href = "Phaser.Tilemap.html" > Tilemap< / a >
< / li >
< li >
< a href = "Phaser.TilemapLayer.html" > TilemapLayer< / a >
< / li >
< li >
< a href = "Phaser.TilemapParser.html" > TilemapParser< / a >
< / li >
< li >
< a href = "Phaser.Tileset.html" > Tileset< / a >
< / li >
2013-10-25 15:54:40 +00:00
< li >
< a href = "Phaser.TileSprite.html" > TileSprite< / a >
< / li >
2013-10-03 01:38:35 +00:00
< li >
< a href = "Phaser.Time.html" > Time< / a >
< / li >
2013-11-28 15:57:09 +00:00
< li >
< a href = "Phaser.Timer.html" > Timer< / a >
< / li >
2014-02-05 06:29:17 +00:00
< li >
< a href = "Phaser.TimerEvent.html" > TimerEvent< / a >
< / li >
2013-10-02 19:18:24 +00:00
< li >
< a href = "Phaser.Touch.html" > Touch< / a >
< / li >
2013-10-03 01:38:35 +00:00
< li >
< a href = "Phaser.Tween.html" > Tween< / a >
< / li >
< li >
< a href = "Phaser.TweenManager.html" > TweenManager< / a >
< / li >
< li >
< a href = "Phaser.Utils.html" > Utils< / a >
< / li >
< li >
< a href = "Phaser.Utils.Debug.html" > Debug< / a >
< / li >
2013-10-02 19:18:24 +00:00
< li >
< a href = "Phaser.World.html" > World< / a >
< / li >
< li >
< a href = "SignalBinding.html" > SignalBinding< / a >
< / li >
< / ul >
< / li >
2014-02-08 07:24:22 +00:00
< li class = "dropdown" >
< a href = "global.html" class = "dropdown-toggle" data-toggle = "dropdown" > Global< b
class="caret">< / b > < / a >
< ul class = "dropdown-menu " >
< li >
< a href = "global.html#canUseNewCanvasBlendModes" > canUseNewCanvasBlendModes< / a >
< / li >
2014-02-18 03:01:51 +00:00
< li >
< a href = "global.html#getBounds" > getBounds< / a >
< / li >
2014-02-08 07:24:22 +00:00
< li >
< a href = "global.html#getNextPowerOfTwo" > getNextPowerOfTwo< / a >
< / li >
< li >
< a href = "global.html#hex2rgb" > hex2rgb< / a >
< / li >
< li >
< a href = "global.html#hitTest" > hitTest< / a >
< / li >
< li >
< a href = "global.html#rgb2hex" > rgb2hex< / a >
< / li >
< / ul >
< / li >
2013-10-02 19:18:24 +00:00
< / ul >
< / div >
< / div >
< div class = "row-fluid" >
< div class = "span12" >
< div id = "main" >
< h1 class = "page-title" > Source: particles/arcade/Emitter.js< / h1 >
< section >
< article >
< pre class = "sunlight-highlight-javascript linenums" > /**
* @author Richard Davey < rich@photonstorm.com>
2014-02-05 06:29:17 +00:00
* @copyright 2014 Photon Storm Ltd.
2013-10-02 19:18:24 +00:00
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* Phaser - ArcadeEmitter
*
* @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
* @extends Phaser.Group
* @param {Phaser.Game} game - Current game instance.
2013-10-03 00:21:08 +00:00
* @param {number} [x=0] - The x coordinate within the Emitter that the particles are emitted from.
* @param {number} [y=0] - The y coordinate within the Emitter that the particles are emitted from.
* @param {number} [maxParticles=50] - The total number of particles in this emitter..
2013-10-02 19:18:24 +00:00
*/
Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) {
/**
2013-10-03 00:21:08 +00:00
* @property {number} maxParticles - The total number of particles in this emitter..
2013-10-02 19:18:24 +00:00
* @default
*/
2013-11-28 15:57:09 +00:00
this.maxParticles = maxParticles || 50;
2013-10-02 19:18:24 +00:00
2013-11-28 15:57:09 +00:00
Phaser.Group.call(this, game);
2013-10-02 19:18:24 +00:00
/**
2013-11-28 15:57:09 +00:00
* @property {string} name - Description.
*/
2013-10-02 19:18:24 +00:00
this.name = 'emitter' + this.game.particles.ID++;
/**
2014-02-05 06:29:17 +00:00
* @property {number} type - Internal Phaser Type value.
* @protected
2013-11-28 15:57:09 +00:00
*/
2013-10-02 19:18:24 +00:00
this.type = Phaser.EMITTER;
/**
2013-11-28 15:57:09 +00:00
* @property {number} x - The X position of the top left corner of the emitter in world space.
* @default
*/
2013-10-02 19:18:24 +00:00
this.x = 0;
/**
2013-11-28 15:57:09 +00:00
* @property {number} y - The Y position of the top left corner of emitter in world space.
* @default
*/
2013-10-02 19:18:24 +00:00
this.y = 0;
/**
2013-11-28 15:57:09 +00:00
* @property {number} width - The width of the emitter. Particles can be randomly generated from anywhere within this box.
* @default
*/
2013-10-02 19:18:24 +00:00
this.width = 1;
/**
* @property {number} height - The height of the emitter. Particles can be randomly generated from anywhere within this box.
* @default
*/
this.height = 1;
/**
2014-02-05 06:29:17 +00:00
* @property {Phaser.Point} minParticleSpeed - The minimum possible velocity of a particle.
* @default
2013-10-02 19:18:24 +00:00
*/
this.minParticleSpeed = new Phaser.Point(-100, -100);
/**
2014-02-05 06:29:17 +00:00
* @property {Phaser.Point} maxParticleSpeed - The maximum possible velocity of a particle.
* @default
2013-10-02 19:18:24 +00:00
*/
this.maxParticleSpeed = new Phaser.Point(100, 100);
/**
2014-02-05 06:29:17 +00:00
* @property {number} minParticleScale - The minimum possible scale of a particle.
2013-10-02 19:18:24 +00:00
* @default
*/
this.minParticleScale = 1;
/**
2014-02-05 06:29:17 +00:00
* @property {number} maxParticleScale - The maximum possible scale of a particle.
2013-11-28 15:57:09 +00:00
* @default
*/
2013-10-02 19:18:24 +00:00
this.maxParticleScale = 1;
/**
2014-02-05 06:29:17 +00:00
* @property {number} minRotation - The minimum possible angular velocity of a particle.
2013-11-28 15:57:09 +00:00
* @default
*/
2013-10-02 19:18:24 +00:00
this.minRotation = -360;
/**
2014-02-05 06:29:17 +00:00
* @property {number} maxRotation - The maximum possible angular velocity of a particle.
2013-11-28 15:57:09 +00:00
* @default
*/
2013-10-02 19:18:24 +00:00
this.maxRotation = 360;
/**
2014-02-05 06:29:17 +00:00
* @property {number} gravity - Sets the `body.gravity.y` of each particle sprite to this value on launch.
2013-11-28 15:57:09 +00:00
* @default
*/
2014-02-05 06:29:17 +00:00
this.gravity = 100;
2013-10-02 19:18:24 +00:00
/**
2014-02-05 06:29:17 +00:00
* @property {any} particleClass - For emitting your own particle class types.
2013-11-28 15:57:09 +00:00
* @default
*/
2013-10-02 19:18:24 +00:00
this.particleClass = null;
/**
2014-02-05 06:29:17 +00:00
* @property {number} particleFriction - The friction component of particles launched from the emitter.
* @default
2013-11-28 15:57:09 +00:00
*/
2014-02-05 06:29:17 +00:00
this.particleFriction = 0;
2013-10-02 19:18:24 +00:00
/**
2014-02-05 06:29:17 +00:00
* @property {number} angularDrag - The angular drag component of particles launched from the emitter if they are rotating.
2013-11-28 15:57:09 +00:00
* @default
*/
2013-10-02 19:18:24 +00:00
this.angularDrag = 0;
/**
2014-02-05 06:29:17 +00:00
* @property {boolean} frequency - How often a particle is emitted in ms (if emitter is started with Explode === false).
2013-11-28 15:57:09 +00:00
* @default
*/
2013-10-02 19:18:24 +00:00
this.frequency = 100;
/**
2014-02-05 06:29:17 +00:00
* @property {number} lifespan - How long each particle lives once it is emitted in ms. Default is 2 seconds. Set lifespan to 'zero' for particles to live forever.
2013-11-28 15:57:09 +00:00
* @default
*/
2013-10-02 19:18:24 +00:00
this.lifespan = 2000;
/**
2014-02-05 06:29:17 +00:00
* @property {Phaser.Point} bounce - How much each particle should bounce on each axis. 1 = full bounce, 0 = no bounce.
2013-11-28 15:57:09 +00:00
*/
2013-10-02 19:18:24 +00:00
this.bounce = new Phaser.Point();
/**
2014-02-05 06:29:17 +00:00
* @property {number} _quantity - Internal helper for deciding how many particles to launch.
2013-11-28 15:57:09 +00:00
* @private
*/
2013-10-02 19:18:24 +00:00
this._quantity = 0;
2013-11-28 15:57:09 +00:00
/**
2014-02-05 06:29:17 +00:00
* @property {number} _timer - Internal helper for deciding when to launch particles or kill them.
2013-11-28 15:57:09 +00:00
* @private
*/
2013-10-02 19:18:24 +00:00
this._timer = 0;
/**
2014-02-05 06:29:17 +00:00
* @property {number} _counter - Internal counter for figuring out how many particles to launch.
2013-11-28 15:57:09 +00:00
* @private
*/
2013-10-02 19:18:24 +00:00
this._counter = 0;
/**
2014-02-05 06:29:17 +00:00
* @property {boolean} _explode - Internal helper for the style of particle emission (all at once, or one at a time).
2013-11-28 15:57:09 +00:00
* @private
*/
2013-10-02 19:18:24 +00:00
this._explode = true;
/**
2014-02-05 06:29:17 +00:00
* @property {boolean} on - Determines whether the emitter is currently emitting particles. It is totally safe to directly toggle this.
2013-11-28 15:57:09 +00:00
* @default
*/
2013-10-02 19:18:24 +00:00
this.on = false;
/**
2014-02-05 06:29:17 +00:00
* @property {boolean} exists - Determines whether the emitter is being updated by the core game loop.
2013-11-28 15:57:09 +00:00
* @default
*/
2013-10-02 19:18:24 +00:00
this.exists = true;
/**
2013-11-28 15:57:09 +00:00
* 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 {boolean} emitX
*/
2013-10-02 19:18:24 +00:00
this.emitX = x;
/**
2013-11-28 15:57:09 +00:00
* 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 {boolean} emitY
*/
2013-10-02 19:18:24 +00:00
this.emitY = y;
2013-11-28 15:57:09 +00:00
2013-10-02 19:18:24 +00:00
};
Phaser.Particles.Arcade.Emitter.prototype = Object.create(Phaser.Group.prototype);
Phaser.Particles.Arcade.Emitter.prototype.constructor = Phaser.Particles.Arcade.Emitter;
/**
* Called automatically by the game loop, decides when to launch particles and when to "die".
* @method Phaser.Particles.Arcade.Emitter#update
*/
Phaser.Particles.Arcade.Emitter.prototype.update = function () {
if (this.on)
{
if (this._explode)
{
2013-11-28 15:57:09 +00:00
this._counter = 0;
2013-10-02 19:18:24 +00:00
do
{
2013-11-28 15:57:09 +00:00
this.emitParticle();
this._counter++;
2013-10-02 19:18:24 +00:00
}
while (this._counter < this._quantity);
this.on = false;
}
else
{
2013-11-28 15:57:09 +00:00
if (this.game.time.now >= this._timer)
{
2013-10-02 19:18:24 +00:00
this.emitParticle();
2013-11-28 15:57:09 +00:00
this._counter++;
2013-10-02 19:18:24 +00:00
if (this._quantity > 0)
{
2013-11-28 15:57:09 +00:00
if (this._counter >= this._quantity)
{
this.on = false;
}
2013-10-02 19:18:24 +00:00
}
this._timer = this.game.time.now + this.frequency;
2013-11-28 15:57:09 +00:00
}
2013-10-02 19:18:24 +00:00
}
}
}
/**
* This function generates a new array of particle sprites to attach to the emitter.
*
* @method Phaser.Particles.Arcade.Emitter#makeParticles
2014-02-05 06:29:17 +00:00
* @param {array|string} keys - A string or an array of strings that the particle sprites will use as their texture. If an array one is picked at random.
* @param {array|number} frames - A frame number, or array of frames that the sprite will use. If an array one is picked at random.
* @param {number} quantity - The number of particles to generate.
* @param {boolean} [collide=false] - Sets the checkCollision.none flag on the particle sprites body.
* @param {boolean} [collideWorldBounds=false] - A particle can be set to collide against the World bounds automatically and rebound back into the World if this is set to true. Otherwise it will leave the World.
* @return {Phaser.Particles.Arcade.Emitter} This Emitter instance.
2013-10-02 19:18:24 +00:00
*/
Phaser.Particles.Arcade.Emitter.prototype.makeParticles = function (keys, frames, quantity, collide, collideWorldBounds) {
2014-02-05 06:29:17 +00:00
if (typeof frames === 'undefined') { frames = 0; }
if (typeof quantity === 'undefined') { quantity = this.maxParticles; }
if (typeof collide === 'undefined') { collide = false; }
if (typeof collideWorldBounds === 'undefined') { collideWorldBounds = false; }
2013-10-02 19:18:24 +00:00
var particle;
var i = 0;
var rndKey = keys;
2014-02-05 06:29:17 +00:00
var rndFrame = frames;
2013-10-02 19:18:24 +00:00
while (i < quantity)
{
2014-02-05 06:29:17 +00:00
if (this.particleClass === null)
2013-10-02 19:18:24 +00:00
{
2014-02-05 06:29:17 +00:00
if (typeof keys === 'object')
2013-10-02 19:18:24 +00:00
{
rndKey = this.game.rnd.pick(keys);
}
2014-02-05 06:29:17 +00:00
if (typeof frames === 'object')
2013-10-02 19:18:24 +00:00
{
rndFrame = this.game.rnd.pick(frames);
}
particle = new Phaser.Sprite(this.game, 0, 0, rndKey, rndFrame);
}
2013-11-28 15:57:09 +00:00
// else
// {
2013-10-02 19:18:24 +00:00
// particle = new this.particleClass(this.game);
2013-11-28 15:57:09 +00:00
// }
2013-10-02 19:18:24 +00:00
2014-02-05 06:29:17 +00:00
if (collide)
2013-10-02 19:18:24 +00:00
{
2014-02-05 06:29:17 +00:00
particle.body.checkCollision.any = true;
particle.body.checkCollision.none = false;
2013-10-02 19:18:24 +00:00
}
else
{
2014-02-05 06:29:17 +00:00
particle.body.checkCollision.none = true;
2013-10-02 19:18:24 +00:00
}
particle.body.collideWorldBounds = collideWorldBounds;
particle.exists = false;
particle.visible = false;
// Center the origin for rotation assistance
particle.anchor.setTo(0.5, 0.5);
this.add(particle);
i++;
}
return this;
}
/**
2014-02-05 06:29:17 +00:00
* Call this function to turn off all the particles and the emitter.
* @method Phaser.Particles.Arcade.Emitter#kill
*/
2013-10-02 19:18:24 +00:00
Phaser.Particles.Arcade.Emitter.prototype.kill = function () {
this.on = false;
this.alive = false;
this.exists = false;
}
/**
2014-02-05 06:29:17 +00:00
* Handy for bringing game objects "back to life". Just sets alive and exists back to true.
* @method Phaser.Particles.Arcade.Emitter#revive
*/
2013-10-02 19:18:24 +00:00
Phaser.Particles.Arcade.Emitter.prototype.revive = function () {
this.alive = true;
this.exists = true;
}
/**
2014-02-05 06:29:17 +00:00
* Call this function to start emitting particles.
* @method Phaser.Particles.Arcade.Emitter#start
* @param {boolean} [explode=true] - Whether the particles should all burst out at once.
* @param {number} [lifespan=0] - How long each particle lives once emitted. 0 = forever.
* @param {number} [frequency=250] - Ignored if Explode is set to true. Frequency is how often to emit a particle in ms.
* @param {number} [quantity=0] - How many particles to launch. 0 = "all of the particles".
*/
2013-10-02 19:18:24 +00:00
Phaser.Particles.Arcade.Emitter.prototype.start = function (explode, lifespan, frequency, quantity) {
2014-02-05 06:29:17 +00:00
if (typeof explode === 'undefined') { explode = true; }
if (typeof lifespan === 'undefined') { lifespan = 0; }
if (typeof frequency === 'undefined') { frequency = 250; }
if (typeof quantity === 'undefined') { quantity = 0; }
2013-10-02 19:18:24 +00:00
this.revive();
this.visible = true;
this.on = true;
this._explode = explode;
this.lifespan = lifespan;
this.frequency = frequency;
if (explode)
{
this._quantity = quantity;
}
else
{
this._quantity += quantity;
}
this._counter = 0;
this._timer = this.game.time.now + frequency;
}
/**
2014-02-05 06:29:17 +00:00
* This function can be used both internally and externally to emit the next particle.
* @method Phaser.Particles.Arcade.Emitter#emitParticle
*/
2013-10-02 19:18:24 +00:00
Phaser.Particles.Arcade.Emitter.prototype.emitParticle = function () {
var particle = this.getFirstExists(false);
if (particle == null)
{
2013-11-28 15:57:09 +00:00
return;
2013-10-02 19:18:24 +00:00
}
if (this.width > 1 || this.height > 1)
{
2013-11-28 15:57:09 +00:00
particle.reset(this.game.rnd.integerInRange(this.left, this.right), this.game.rnd.integerInRange(this.top, this.bottom));
2013-10-02 19:18:24 +00:00
}
else
{
2013-11-28 15:57:09 +00:00
particle.reset(this.emitX, this.emitY);
2013-10-02 19:18:24 +00:00
}
particle.lifespan = this.lifespan;
particle.body.bounce.setTo(this.bounce.x, this.bounce.y);
if (this.minParticleSpeed.x != this.maxParticleSpeed.x)
{
particle.body.velocity.x = this.game.rnd.integerInRange(this.minParticleSpeed.x, this.maxParticleSpeed.x);
}
else
{
particle.body.velocity.x = this.minParticleSpeed.x;
}
if (this.minParticleSpeed.y != this.maxParticleSpeed.y)
{
particle.body.velocity.y = this.game.rnd.integerInRange(this.minParticleSpeed.y, this.maxParticleSpeed.y);
}
else
{
particle.body.velocity.y = this.minParticleSpeed.y;
}
particle.body.gravity.y = this.gravity;
if (this.minRotation != this.maxRotation)
{
particle.body.angularVelocity = this.game.rnd.integerInRange(this.minRotation, this.maxRotation);
}
else
{
particle.body.angularVelocity = this.minRotation;
}
if (this.minParticleScale !== 1 || this.maxParticleScale !== 1)
{
var scale = this.game.rnd.realInRange(this.minParticleScale, this.maxParticleScale);
particle.scale.setTo(scale, scale);
}
2014-02-05 06:29:17 +00:00
particle.body.friction = this.particleFriction;
2013-10-02 19:18:24 +00:00
particle.body.angularDrag = this.angularDrag;
}
/**
* A more compact way of setting the width and height of the emitter.
* @method Phaser.Particles.Arcade.Emitter#setSize
2014-02-05 06:29:17 +00:00
* @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.
2013-10-02 19:18:24 +00:00
*/
Phaser.Particles.Arcade.Emitter.prototype.setSize = function (width, height) {
this.width = width;
this.height = height;
}
/**
* A more compact way of setting the X velocity range of the emitter.
* @method Phaser.Particles.Arcade.Emitter#setXSpeed
2014-02-05 06:29:17 +00:00
* @param {number} [min=0] - The minimum value for this range.
* @param {number} [max=0] - The maximum value for this range.
2013-10-02 19:18:24 +00:00
*/
Phaser.Particles.Arcade.Emitter.prototype.setXSpeed = function (min, max) {
2013-11-28 15:57:09 +00:00
min = min || 0;
max = max || 0;
2013-10-02 19:18:24 +00:00
this.minParticleSpeed.x = min;
this.maxParticleSpeed.x = max;
}
/**
* A more compact way of setting the Y velocity range of the emitter.
* @method Phaser.Particles.Arcade.Emitter#setYSpeed
2014-02-05 06:29:17 +00:00
* @param {number} [min=0] - The minimum value for this range.
* @param {number} [max=0] - The maximum value for this range.
2013-10-02 19:18:24 +00:00
*/
Phaser.Particles.Arcade.Emitter.prototype.setYSpeed = function (min, max) {
2013-11-28 15:57:09 +00:00
min = min || 0;
max = max || 0;
2013-10-02 19:18:24 +00:00
this.minParticleSpeed.y = min;
this.maxParticleSpeed.y = max;
}
/**
* A more compact way of setting the angular velocity constraints of the emitter.
* @method Phaser.Particles.Arcade.Emitter#setRotation
2014-02-05 06:29:17 +00:00
* @param {number} [min=0] - The minimum value for this range.
* @param {number} [max=0] - The maximum value for this range.
2013-10-02 19:18:24 +00:00
*/
Phaser.Particles.Arcade.Emitter.prototype.setRotation = function (min, max) {
2013-11-28 15:57:09 +00:00
min = min || 0;
max = max || 0;
2013-10-02 19:18:24 +00:00
this.minRotation = min;
this.maxRotation = max;
}
/**
2014-02-05 06:29:17 +00:00
* Change the emitters center to match the center of any object with a `center` property, such as a Sprite.
2013-10-02 19:18:24 +00:00
* @method Phaser.Particles.Arcade.Emitter#at
2014-02-05 06:29:17 +00:00
* @param {object|Phaser.Sprite} object - The object that you wish to match the center with.
2013-10-02 19:18:24 +00:00
*/
Phaser.Particles.Arcade.Emitter.prototype.at = function (object) {
2014-02-05 06:29:17 +00:00
if (object.center)
{
this.emitX = object.center.x;
this.emitY = object.center.y;
}
2013-10-02 19:18:24 +00:00
}
/**
* The emitters alpha value.
* @name Phaser.Particles.Arcade.Emitter#alpha
* @property {number} alpha - Gets or sets the alpha value of the Emitter.
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "alpha", {
get: function () {
return this._container.alpha;
},
set: function (value) {
this._container.alpha = value;
}
});
2014-02-08 07:24:22 +00:00
*/
2013-10-02 19:18:24 +00:00
/**
* The emitter visible state.
* @name Phaser.Particles.Arcade.Emitter#visible
* @property {boolean} visible - Gets or sets the Emitter visible state.
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "visible", {
get: function () {
return this._container.visible;
},
set: function (value) {
this._container.visible = value;
}
});
2014-02-08 07:24:22 +00:00
*/
2013-10-02 19:18:24 +00:00
/**
* @name Phaser.Particles.Arcade.Emitter#x
* @property {number} x - Gets or sets the x position of the Emitter.
*/
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "x", {
get: function () {
return this.emitX;
},
set: function (value) {
this.emitX = value;
}
});
/**
* @name Phaser.Particles.Arcade.Emitter#y
* @property {number} y - Gets or sets the y position of the Emitter.
*/
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "y", {
get: function () {
return this.emitY;
},
set: function (value) {
this.emitY = value;
}
});
/**
* @name Phaser.Particles.Arcade.Emitter#left
* @property {number} left - Gets the left position of the Emitter.
* @readonly
*/
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "left", {
get: function () {
return Math.floor(this.x - (this.width / 2));
}
});
/**
* @name Phaser.Particles.Arcade.Emitter#right
* @property {number} right - Gets the right position of the Emitter.
* @readonly
*/
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "right", {
get: function () {
return Math.floor(this.x + (this.width / 2));
}
});
/**
* @name Phaser.Particles.Arcade.Emitter#top
* @property {number} top - Gets the top position of the Emitter.
* @readonly
*/
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "top", {
get: function () {
return Math.floor(this.y - (this.height / 2));
}
});
/**
* @name Phaser.Particles.Arcade.Emitter#bottom
* @property {number} bottom - Gets the bottom position of the Emitter.
* @readonly
*/
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "bottom", {
get: function () {
return Math.floor(this.y + (this.height / 2));
}
});
< / pre >
< / article >
< / section >
< / div >
< div class = "clearfix" > < / div >
< footer >
< span class = "copyright" >
2014-02-05 06:29:17 +00:00
Phaser Copyright © 2012-2014 Photon Storm Ltd.
2013-10-02 19:18:24 +00:00
< / span >
< br / >
< span class = "jsdoc-message" >
2013-10-25 15:54:40 +00:00
Documentation generated by < a href = "https://github.com/jsdoc3/jsdoc" > JSDoc 3.3.0-dev< / a >
2014-02-24 12:14:30 +00:00
on Mon Feb 24 2014 12:11:34 GMT-0000 (GMT) using the < a href = "https://github.com/terryweiss/docstrap" > DocStrap template< / a > .
2013-10-02 19:18:24 +00:00
< / span >
< / footer >
< / div >
< br clear = "both" >
< / div >
< / div >
< script src = "scripts/sunlight.js" > < / script >
< script src = "scripts/sunlight.javascript.js" > < / script >
< script src = "scripts/sunlight-plugin.doclinks.js" > < / script >
< script src = "scripts/sunlight-plugin.linenumbers.js" > < / script >
< script src = "scripts/sunlight-plugin.menu.js" > < / script >
< script src = "scripts/jquery.min.js" > < / script >
< script src = "scripts/jquery.scrollTo.js" > < / script >
< script src = "scripts/jquery.localScroll.js" > < / script >
< script src = "scripts/bootstrap-dropdown.js" > < / script >
< script src = "scripts/toc.js" > < / script >
< script > Sunlight . highlightAll ( { lineNumbers : true , showMenu : true , enableDoclinks : true } ) ; < / script >
< script >
$( function () {
$( "#toc" ).toc( {
selectors : "h1,h2,h3,h4",
showAndHide : false,
scrollTo : 60
} );
$( "#toc>ul" ).addClass( "nav nav-pills nav-stacked" );
$( "#main span[id^='toc']" ).addClass( "toc-shim" );
} );
< / script >
< / body >
< / html >