diff --git a/dist/modules/animated-particle.js b/dist/modules/animated-particle.js index 743f23a1..1ffec063 100644 --- a/dist/modules/animated-particle.js +++ b/dist/modules/animated-particle.js @@ -1,6 +1,7 @@ /*! PixiParticles 1.5.0 */ /** -* @module cloudkid +* @module Animated Particle +* @namespace cloudkid */ (function(cloudkid, undefined) { @@ -12,8 +13,34 @@ var useAPI3 = ParticleUtils.useAPI3; /** - * An individual particle image with an animation. While this class may be functional, it - * has not gotten thorough testing or examples yet, and is not considered to be release ready. + * An individual particle image with an animation. Art data passed to the emitter must be + * formatted in a particular way for AnimatedParticle to be able to handle it: + * + * { + * //framerate is required. It is the animation speed of the particle in frames per + * //second. + * //A value of "matchLife" causes the animation to match the lifetime of an individual + * //particle, instead of at a constant framerate. This causes the animation to play + * //through one time, completing when the particle expires. + * framerate: 6, + * //loop is optional, and defaults to false. + * loop: true, + * //textures is required, and can be an array of any (non-zero) length. + * textures: [ + * //each entry represents a single texture that should be used for one or more + * //frames. Any strings will be converted to Textures with Texture.fromImage(). + * //Instances of PIXI.Texture will be used directly. + * "animFrame1.png", + * //entries can be an object with a 'count' property, telling AnimatedParticle to + * //use that texture for 'count' frames sequentially. + * { + * texture: "animFrame2.png", + * count: 3 + * }, + * "animFrame3.png" + * ] + * } + * * @class AnimatedParticle * @constructor * @param {Emitter} emitter The emitter that controls this AnimatedParticle. @@ -132,6 +159,14 @@ s.destroy.call(this); }; + /** + * Checks over the art that was passed to the Emitter's init() function, to do any special + * modifications to prepare it ahead of time. + * @method parseArt + * @static + * @param {Array} art The array of art data, properly formatted for AnimatedParticle. + * @return {Array} The art, after any needed modifications. + */ AnimatedParticle.parseArt = function(art) { var i, data, output = [], j, textures, tex, outTextures; diff --git a/dist/modules/path-particle.js b/dist/modules/path-particle.js index fc8ac1d2..638832f3 100644 --- a/dist/modules/path-particle.js +++ b/dist/modules/path-particle.js @@ -1,6 +1,7 @@ /*! PixiParticles 1.5.0 */ /** -* @module cloudkid +* @module Path Particle +* @namespace cloudkid */ (function(cloudkid, undefined) { @@ -185,6 +186,8 @@ /** * Checks over the art that was passed to the Emitter's init() function, to do any special * modifications to prepare it ahead of time. This just runs Particle.parseArt(). + * @method parseArt + * @static * @param {Array} art The array of art data. For Particle, it should be an array of Textures. * Any strings in the array will be converted to Textures via * Texture.fromImage(). @@ -199,6 +202,8 @@ * Parses extra emitter data to ensure it is set up for this particle class. * PathParticle checks for the existence of path data, and parses the path data for use * by particle instances. + * @method parseData + * @static * @param {Object} extraData The extra data from the particle config. * @return {Object} The parsed extra data. */ diff --git a/dist/pixi-particles.js b/dist/pixi-particles.js index aaffa193..2ef0f6c6 100644 --- a/dist/pixi-particles.js +++ b/dist/pixi-particles.js @@ -1,6 +1,7 @@ /*! PixiParticles 1.5.0 */ /** -* @module cloudkid +* @module Pixi Particles +* @namespace cloudkid */ (function(undefined) { @@ -182,7 +183,8 @@ cloudkid.ParticleUtils = ParticleUtils; /** - * @module global + * @module Pixi Particles + * @namespace window */ /** * Add methods to Array @@ -226,7 +228,8 @@ } }()); /** -* @module cloudkid +* @module Pixi Particles +* @namespace cloudkid */ (function(cloudkid, undefined) { @@ -633,6 +636,8 @@ /** * Checks over the art that was passed to the Emitter's init() function, to do any special * modifications to prepare it ahead of time. + * @method parseArt + * @static * @param {Array} art The array of art data. For Particle, it should be an array of Textures. * Any strings in the array will be converted to Textures via * Texture.fromImage(). @@ -664,13 +669,27 @@ return art; }; + + /** + * Parses extra emitter data to ensure it is set up for this particle class. + * Particle does nothing to the extra data. + * @method parseData + * @static + * @param {Object} extraData The extra data from the particle config. + * @return {Object} The parsed extra data. + */ + Particle.parseData = function(extraData) + { + return extraData; + }; cloudkid.Particle = Particle; }(cloudkid)); /** -* @module cloudkid +* @module Pixi Particles +* @namespace cloudkid */ (function(cloudkid, undefined) { diff --git a/dist/pixi-particles.min.js b/dist/pixi-particles.min.js index ec0b84e9..5131a5ee 100644 --- a/dist/pixi-particles.min.js +++ b/dist/pixi-particles.min.js @@ -1,2 +1,2 @@ /*! PixiParticles 1.5.0 */ -!function(){"use strict";!function(a){"use strict";window.cloudkid=window.cloudkid||{};var b=PIXI.BLEND_MODES||PIXI.blendModes,c={},d=c.DEG_TO_RADS=Math.PI/180;c.useAPI3=!1;var e=PIXI.VERSION;e&&parseInt(e.substring(0,e.indexOf(".")))>=3&&(c.useAPI3=!0),c.rotatePoint=function(a,b){if(a){a*=d;var c=Math.sin(a),e=Math.cos(a),f=b.x*e-b.y*c,g=b.x*c+b.y*e;b.x=f,b.y=g}},c.combineRGBComponents=function(a,b,c){return a<<16|b<<8|c},c.normalize=function(a){var b=1/c.length(a);a.x*=b,a.y*=b},c.scaleBy=function(a,b){a.x*=b,a.y*=b},c.length=function(a){return Math.sqrt(a.x*a.x+a.y*a.y)},c.hexToRGB=function(a,b){b?b.length=0:b=[],"#"==a.charAt(0)?a=a.substr(1):0===a.indexOf("0x")&&(a=a.substr(2));var c;return 8==a.length&&(c=a.substr(0,2),a=a.substr(2)),b.push(parseInt(a.substr(0,2),16)),b.push(parseInt(a.substr(2,2),16)),b.push(parseInt(a.substr(4,2),16)),c&&b.push(parseInt(c,16)),b},c.generateEase=function(a){var b=a.length,c=1/b,d=function(d){var e,f,g=b*d|0;return e=(d-g*c)*b,f=a[g]||a[b-1],f.s+e*(2*(1-e)*(f.cp-f.s)+e*(f.e-f.s))};return d},c.getBlendMode=function(a){if(!a)return b.NORMAL;for(a=a.toUpperCase();a.indexOf(" ")>=0;)a=a.replace(" ","_");return b[a]||b.NORMAL},cloudkid.ParticleUtils=c,Array.prototype.shuffle||Object.defineProperty(Array.prototype,"shuffle",{enumerable:!1,writable:!1,value:function(){for(var a,b,c=this.length;c;a=Math.floor(Math.random()*c),b=this[--c],this[c]=this[a],this[a]=b);return this}}),Array.prototype.random||Object.defineProperty(Array.prototype,"random",{enumerable:!1,writable:!1,value:function(){return this[Math.floor(Math.random()*this.length)]}})}(),function(a,b){"use strict";var c,d=a.ParticleUtils,e=PIXI.Sprite,f=d.useAPI3;if(!f){var g=document.createElement("canvas");g.width=g.height=1,c=PIXI.Texture.fromCanvas(g)}var h=function(a){f?e.call(this):e.call(this,c),this.emitter=a,this.anchor.x=this.anchor.y=.5,this.velocity=new PIXI.Point,this.maxLife=0,this.age=0,this.ease=null,this.extraData=null,this.startAlpha=0,this.endAlpha=0,this.startSpeed=0,this.endSpeed=0,this.acceleration=null,this.startScale=0,this.endScale=0,this.startColor=null,this._sR=0,this._sG=0,this._sB=0,this.endColor=null,this._eR=0,this._eG=0,this._eB=0,this._doAlpha=!1,this._doScale=!1,this._doSpeed=!1,this._doColor=!1,this._doNormalMovement=!1,this._oneOverLife=0,this.init=this.init,this.Particle_init=this.Particle_init,this.update=this.update,this.Particle_update=this.Particle_update,this.applyArt=this.applyArt,this.kill=this.kill},i=h.prototype=Object.create(e.prototype);i.init=i.Particle_init=function(){this.age=0,this.velocity.x=this.startSpeed,this.velocity.y=0,d.rotatePoint(this.rotation,this.velocity),this.rotation*=d.DEG_TO_RADS,this.rotationSpeed*=d.DEG_TO_RADS,this.alpha=this.startAlpha,this.scale.x=this.scale.y=this.startScale,this.startColor&&(this._sR=this.startColor[0],this._sG=this.startColor[1],this._sB=this.startColor[2],this.endColor&&(this._eR=this.endColor[0],this._eG=this.endColor[1],this._eB=this.endColor[2])),this._doAlpha=this.startAlpha!=this.endAlpha,this._doSpeed=this.startSpeed!=this.endSpeed,this._doScale=this.startScale!=this.endScale,this._doColor=!!this.endColor,this._doNormalMovement=this._doSpeed||0!==this.startSpeed||this.acceleration,this._oneOverLife=1/this.maxLife,this.tint=d.combineRGBComponents(this._sR,this._sG,this._sB),this.visible=!0},i.applyArt=function(a){f?this.texture=a:this.setTexture(a)},i.update=i.Particle_update=function(a){if(this.age+=a,this.age>=this.maxLife)return this.kill(),-1;var b=this.age*this._oneOverLife;if(this.ease&&(b=4==this.ease.length?this.ease(b,0,1,1):this.ease(b)),this._doAlpha&&(this.alpha=(this.endAlpha-this.startAlpha)*b+this.startAlpha),this._doScale){var c=(this.endScale-this.startScale)*b+this.startScale;this.scale.x=this.scale.y=c}if(this._doNormalMovement){if(this._doSpeed){var e=(this.endSpeed-this.startSpeed)*b+this.startSpeed;d.normalize(this.velocity),d.scaleBy(this.velocity,e)}else this.acceleration&&(this.velocity.x+=this.acceleration.x*a,this.velocity.y+=this.acceleration.y*a);this.position.x+=this.velocity.x*a,this.position.y+=this.velocity.y*a}if(this._doColor){var f=(this._eR-this._sR)*b+this._sR,g=(this._eG-this._sG)*b+this._sG,h=(this._eB-this._sB)*b+this._sB;this.tint=d.combineRGBComponents(f,g,h)}return 0!==this.rotationSpeed?this.rotation+=this.rotationSpeed*a:this.acceleration&&(this.rotation=Math.atan2(this.velocity.y,this.velocity.x)),b},i.kill=function(){this.emitter.recycle(this)},i.destroy=function(){this.emitter=null,this.velocity=null,this.startColor=this.endColor=null,this.ease=null},h.parseArt=function(a){var b;for(b=a.length;b>=0;--b)"string"==typeof a[b]&&(a[b]=PIXI.Texture.fromImage(a[b]));return a},a.Particle=h}(cloudkid),function(a,b){"use strict";var c=a.ParticleUtils,d=a.Particle,e=PIXI.ParticleContainer,f=function(a,b,c){this._particleConstructor=d,this.particleImages=null,this.startAlpha=1,this.endAlpha=1,this.startSpeed=0,this.endSpeed=0,this.acceleration=null,this.startScale=1,this.endScale=1,this.minimumScaleMultiplier=1,this.startColor=null,this.endColor=null,this.minLifetime=0,this.maxLifetime=0,this.minStartRotation=0,this.maxStartRotation=0,this.minRotationSpeed=0,this.maxRotationSpeed=0,this.particleBlendMode=0,this.customEase=null,this.extraData=null,this.frequency=0,this.maxParticles=1e3,this.emitterLifetime=-1,this.spawnPos=null,this.spawnType=null,this._spawnFunc=null,this.spawnRect=null,this.spawnCircle=null,this.particlesPerWave=1,this.particleSpacing=0,this.angleStart=0,this.rotation=0,this.ownerPos=null,this._prevEmitterPos=null,this._prevPosIsValid=!1,this._posChanged=!1,this._parentIsPC=!1,this._parent=null,this.addAtBack=!1,this._emit=!1,this._spawnTimer=0,this._emitterLife=-1,this._activeParticles=[],this._pool=[],this._origConfig=null,this._origArt=null,this.parent=a,b&&c&&this.init(b,c),this.recycle=this.recycle,this.update=this.update,this.rotate=this.rotate,this.updateSpawnPos=this.updateSpawnPos,this.updateOwnerPos=this.updateOwnerPos},g=f.prototype={},h=new PIXI.Point;Object.defineProperty(g,"particleConstructor",{get:function(){return this._particleConstructor},set:function(a){a!=this._particleConstructor&&(this._particleConstructor=a,this.cleanup(),this._activeParticles.length&&(this._activeParticles.length=0),this._pool.length&&(this._pool.length=0),this._origConfig&&this._origArt&&this.init(this._origArt,this._origConfig))}}),Object.defineProperty(g,"parent",{get:function(){return this._parent},set:function(a){this.cleanup(),this._parent=a,this._parentIsPC=e&&a&&a instanceof e}}),g.init=function(a,b){if(a&&b){this.cleanup(),this._origConfig=b,this._origArt=a,a=Array.isArray(a)?a.slice():[a];var d=this._particleConstructor;this.particleImages=d.parseArt?d.parseArt(a):a,b.alpha?(this.startAlpha=b.alpha.start,this.endAlpha=b.alpha.end):this.startAlpha=this.endAlpha=1,b.speed?(this.startSpeed=b.speed.start,this.endSpeed=b.speed.end):this.startSpeed=this.endSpeed=0;var e=b.acceleration;e&&(e.x||e.y)?(this.endSpeed=this.startSpeed,this.acceleration=new PIXI.Point(e.x,e.y)):this.acceleration=null,b.scale?(this.startScale=b.scale.start,this.endScale=b.scale.end,this.minimumScaleMultiplier=b.scale.minimumScaleMultiplier||1):this.startScale=this.endScale=this.minimumScaleMultiplier=1,b.color&&(this.startColor=c.hexToRGB(b.color.start),b.color.start!=b.color.end?this.endColor=c.hexToRGB(b.color.end):this.endColor=null),b.startRotation?(this.minStartRotation=b.startRotation.min,this.maxStartRotation=b.startRotation.max):this.minStartRotation=this.maxStartRotation=0,b.rotationSpeed?(this.minRotationSpeed=b.rotationSpeed.min,this.maxRotationSpeed=b.rotationSpeed.max):this.minRotationSpeed=this.maxRotationSpeed=0,this.minLifetime=b.lifetime.min,this.maxLifetime=b.lifetime.max,this.particleBlendMode=c.getBlendMode(b.blendMode),b.ease?this.customEase="function"==typeof b.ease?b.ease:c.generateEase(b.ease):this.customEase=null,d.parseData?this.extraData=d.parseData(b.extraData):this.extraData=b.extraData||null,this.spawnRect=this.spawnCircle=null,this.particlesPerWave=1,this.particleSpacing=0,this.angleStart=0;var f;switch(b.spawnType){case"rect":this.spawnType="rect",this._spawnFunc=this._spawnRect;var g=b.spawnRect;this.spawnRect=new PIXI.Rectangle(g.x,g.y,g.w,g.h);break;case"circle":this.spawnType="circle",this._spawnFunc=this._spawnCircle,f=b.spawnCircle,this.spawnCircle=new PIXI.Circle(f.x,f.y,f.r);break;case"ring":this.spawnType="ring",this._spawnFunc=this._spawnRing,f=b.spawnCircle,this.spawnCircle=new PIXI.Circle(f.x,f.y,f.r),this.spawnCircle.minRadius=f.minR;break;case"burst":this.spawnType="burst",this._spawnFunc=this._spawnBurst,this.particlesPerWave=b.particlesPerWave,this.particleSpacing=b.particleSpacing,this.angleStart=b.angleStart?b.angleStart:0;break;case"point":this.spawnType="point",this._spawnFunc=this._spawnPoint;break;default:this.spawnType="point",this._spawnFunc=this._spawnPoint}this.frequency=b.frequency,this.emitterLifetime=b.emitterLifetime||-1,this.maxParticles=b.maxParticles>0?b.maxParticles:1e3,this.addAtBack=!!b.addAtBack,this.rotation=0,this.ownerPos=new PIXI.Point,this.spawnPos=new PIXI.Point(b.pos.x,b.pos.y),this._prevEmitterPos=this.spawnPos.clone(),this._prevPosIsValid=!1,this._spawnTimer=0,this.emit=!0}},g.recycle=function(a){var b=this._activeParticles,c=b.indexOf(a);c=0;--b)c[b].update(a);var d,e;this._prevPosIsValid&&(d=this._prevEmitterPos.x,e=this._prevEmitterPos.y);var f=this.ownerPos.x+this.spawnPos.x,g=this.ownerPos.y+this.spawnPos.y;if(this.emit)for(this._spawnTimer-=a;this._spawnTimer<=0;){if(this._emitterLife>0&&(this._emitterLife-=this.frequency,this._emitterLife<=0)){this._spawnTimer=0,this._emitterLife=0,this.emit=!1;break}if(this._activeParticles.length>=this.maxParticles)this._spawnTimer+=this.frequency;else{var h;if(h=this.minLifetime==this.maxLifetime?this.minLifetime:Math.random()*(this.maxLifetime-this.minLifetime)+this.minLifetime,-this._spawnTimerb;++b){var m=this._pool.length?this._pool.pop():new this.particleConstructor(this);if(this.particleImages.length>1?m.applyArt(this.particleImages.random()):m.applyArt(this.particleImages[0]),m.startAlpha=this.startAlpha,m.endAlpha=this.endAlpha,m.startSpeed=this.startSpeed,m.endSpeed=this.endSpeed,m.acceleration=this.acceleration,1!=this.minimumScaleMultiplier){var n=Math.random()*(1-this.minimumScaleMultiplier)+this.minimumScaleMultiplier;m.startScale=this.startScale*n,m.endScale=this.endScale*n}else m.startScale=this.startScale,m.endScale=this.endScale;if(m.startColor=this.startColor,m.endColor=this.endColor,this.minRotationSpeed==this.maxRotationSpeed?m.rotationSpeed=this.minRotationSpeed:m.rotationSpeed=Math.random()*(this.maxRotationSpeed-this.minRotationSpeed)+this.minRotationSpeed,m.maxLife=h,m.blendMode=this.particleBlendMode,m.ease=this.customEase,m.extraData=this.extraData,this._spawnFunc(m,i,j,b),m.init(),m.update(-this._spawnTimer),this._parentIsPC&&m.parent){var o=this._parent.children,p=o.indexOf(m);1>p?o.shift():p==o.length-1?o.pop():o.splice(p,1),this.addAtBack?o.unshift(m):o.push(m)}else this.addAtBack?this._parent.addChildAt(m,0):this._parent.addChild(m);c.push(m)}}this._spawnTimer+=this.frequency}}this._posChanged&&(this._prevEmitterPos.x=f,this._prevEmitterPos.y=g,this._prevPosIsValid=!0,this._posChanged=!1)},g._spawnPoint=function(a,b,c,d){this.minStartRotation==this.maxStartRotation?a.rotation=this.minStartRotation+this.rotation:a.rotation=Math.random()*(this.maxStartRotation-this.minStartRotation)+this.minStartRotation+this.rotation,a.position.x=b,a.position.y=c},g._spawnRect=function(a,b,d,e){this.minStartRotation==this.maxStartRotation?a.rotation=this.minStartRotation+this.rotation:a.rotation=Math.random()*(this.maxStartRotation-this.minStartRotation)+this.minStartRotation+this.rotation,h.x=Math.random()*this.spawnRect.width+this.spawnRect.x,h.y=Math.random()*this.spawnRect.height+this.spawnRect.y,0!==this.rotation&&c.rotatePoint(this.rotation,h),a.position.x=b+h.x,a.position.y=d+h.y},g._spawnCircle=function(a,b,d,e){this.minStartRotation==this.maxStartRotation?a.rotation=this.minStartRotation+this.rotation:a.rotation=Math.random()*(this.maxStartRotation-this.minStartRotation)+this.minStartRotation+this.rotation,h.x=Math.random()*this.spawnCircle.radius,h.y=0,c.rotatePoint(360*Math.random(),h),h.x+=this.spawnCircle.x,h.y+=this.spawnCircle.y,0!==this.rotation&&c.rotatePoint(this.rotation,h),a.position.x=b+h.x,a.position.y=d+h.y},g._spawnRing=function(a,b,d,e){var f=this.spawnCircle;this.minStartRotation==this.maxStartRotation?a.rotation=this.minStartRotation+this.rotation:a.rotation=Math.random()*(this.maxStartRotation-this.minStartRotation)+this.minStartRotation+this.rotation,f.minRadius==f.radius?h.x=Math.random()*(f.radius-f.minRadius)+f.minRadius:h.x=f.radius,h.y=0;var g=360*Math.random();a.rotation+=g,c.rotatePoint(g,h),h.x+=this.spawnCircle.x,h.y+=this.spawnCircle.y,0!==this.rotation&&c.rotatePoint(this.rotation,h),a.position.x=b+h.x,a.position.y=d+h.y},g._spawnBurst=function(a,b,c,d){0===this.particleSpacing?a.rotation=360*Math.random():a.rotation=this.angleStart+this.particleSpacing*d+this.rotation,a.position.x=b,a.position.y=c},g.cleanup=function(){for(var a=this._activeParticles.length-1;a>=0;--a){var b=this._activeParticles[a];this.recycle(b),b.parent&&b.parent.removeChild(b)}},g.destroy=function(){this.cleanup();for(var a=this._pool.length-1;a>=0;--a)this._pool[a].destroy();this._pool=null,this._activeParticles=null,this._parent=null,this.particleImages=null,this.spawnPos=null,this.ownerPos=null,this.startColor=null,this.endColor=null,this.customEase=null},a.Emitter=f}(cloudkid);}(); \ No newline at end of file +!function(){"use strict";!function(a){"use strict";window.cloudkid=window.cloudkid||{};var b=PIXI.BLEND_MODES||PIXI.blendModes,c={},d=c.DEG_TO_RADS=Math.PI/180;c.useAPI3=!1;var e=PIXI.VERSION;e&&parseInt(e.substring(0,e.indexOf(".")))>=3&&(c.useAPI3=!0),c.rotatePoint=function(a,b){if(a){a*=d;var c=Math.sin(a),e=Math.cos(a),f=b.x*e-b.y*c,g=b.x*c+b.y*e;b.x=f,b.y=g}},c.combineRGBComponents=function(a,b,c){return a<<16|b<<8|c},c.normalize=function(a){var b=1/c.length(a);a.x*=b,a.y*=b},c.scaleBy=function(a,b){a.x*=b,a.y*=b},c.length=function(a){return Math.sqrt(a.x*a.x+a.y*a.y)},c.hexToRGB=function(a,b){b?b.length=0:b=[],"#"==a.charAt(0)?a=a.substr(1):0===a.indexOf("0x")&&(a=a.substr(2));var c;return 8==a.length&&(c=a.substr(0,2),a=a.substr(2)),b.push(parseInt(a.substr(0,2),16)),b.push(parseInt(a.substr(2,2),16)),b.push(parseInt(a.substr(4,2),16)),c&&b.push(parseInt(c,16)),b},c.generateEase=function(a){var b=a.length,c=1/b,d=function(d){var e,f,g=b*d|0;return e=(d-g*c)*b,f=a[g]||a[b-1],f.s+e*(2*(1-e)*(f.cp-f.s)+e*(f.e-f.s))};return d},c.getBlendMode=function(a){if(!a)return b.NORMAL;for(a=a.toUpperCase();a.indexOf(" ")>=0;)a=a.replace(" ","_");return b[a]||b.NORMAL},cloudkid.ParticleUtils=c,Array.prototype.shuffle||Object.defineProperty(Array.prototype,"shuffle",{enumerable:!1,writable:!1,value:function(){for(var a,b,c=this.length;c;a=Math.floor(Math.random()*c),b=this[--c],this[c]=this[a],this[a]=b);return this}}),Array.prototype.random||Object.defineProperty(Array.prototype,"random",{enumerable:!1,writable:!1,value:function(){return this[Math.floor(Math.random()*this.length)]}})}(),function(a,b){"use strict";var c,d=a.ParticleUtils,e=PIXI.Sprite,f=d.useAPI3;if(!f){var g=document.createElement("canvas");g.width=g.height=1,c=PIXI.Texture.fromCanvas(g)}var h=function(a){f?e.call(this):e.call(this,c),this.emitter=a,this.anchor.x=this.anchor.y=.5,this.velocity=new PIXI.Point,this.maxLife=0,this.age=0,this.ease=null,this.extraData=null,this.startAlpha=0,this.endAlpha=0,this.startSpeed=0,this.endSpeed=0,this.acceleration=null,this.startScale=0,this.endScale=0,this.startColor=null,this._sR=0,this._sG=0,this._sB=0,this.endColor=null,this._eR=0,this._eG=0,this._eB=0,this._doAlpha=!1,this._doScale=!1,this._doSpeed=!1,this._doColor=!1,this._doNormalMovement=!1,this._oneOverLife=0,this.next=null,this.prev=null,this.init=this.init,this.Particle_init=this.Particle_init,this.update=this.update,this.Particle_update=this.Particle_update,this.applyArt=this.applyArt,this.kill=this.kill},i=h.prototype=Object.create(e.prototype);i.init=i.Particle_init=function(){this.age=0,this.velocity.x=this.startSpeed,this.velocity.y=0,d.rotatePoint(this.rotation,this.velocity),this.rotation*=d.DEG_TO_RADS,this.rotationSpeed*=d.DEG_TO_RADS,this.alpha=this.startAlpha,this.scale.x=this.scale.y=this.startScale,this.startColor&&(this._sR=this.startColor[0],this._sG=this.startColor[1],this._sB=this.startColor[2],this.endColor&&(this._eR=this.endColor[0],this._eG=this.endColor[1],this._eB=this.endColor[2])),this._doAlpha=this.startAlpha!=this.endAlpha,this._doSpeed=this.startSpeed!=this.endSpeed,this._doScale=this.startScale!=this.endScale,this._doColor=!!this.endColor,this._doNormalMovement=this._doSpeed||0!==this.startSpeed||this.acceleration,this._oneOverLife=1/this.maxLife,this.tint=d.combineRGBComponents(this._sR,this._sG,this._sB),this.visible=!0},i.applyArt=function(a){f?this.texture=a:this.setTexture(a)},i.update=i.Particle_update=function(a){if(this.age+=a,this.age>=this.maxLife)return this.kill(),-1;var b=this.age*this._oneOverLife;if(this.ease&&(b=4==this.ease.length?this.ease(b,0,1,1):this.ease(b)),this._doAlpha&&(this.alpha=(this.endAlpha-this.startAlpha)*b+this.startAlpha),this._doScale){var c=(this.endScale-this.startScale)*b+this.startScale;this.scale.x=this.scale.y=c}if(this._doNormalMovement){if(this._doSpeed){var e=(this.endSpeed-this.startSpeed)*b+this.startSpeed;d.normalize(this.velocity),d.scaleBy(this.velocity,e)}else this.acceleration&&(this.velocity.x+=this.acceleration.x*a,this.velocity.y+=this.acceleration.y*a);this.position.x+=this.velocity.x*a,this.position.y+=this.velocity.y*a}if(this._doColor){var f=(this._eR-this._sR)*b+this._sR,g=(this._eG-this._sG)*b+this._sG,h=(this._eB-this._sB)*b+this._sB;this.tint=d.combineRGBComponents(f,g,h)}return 0!==this.rotationSpeed?this.rotation+=this.rotationSpeed*a:this.acceleration&&(this.rotation=Math.atan2(this.velocity.y,this.velocity.x)),b},i.kill=function(){this.emitter.recycle(this)},i.destroy=function(){this.emitter=this.velocity=this.startColor=this.endColor=this.ease=this.next=this.prev=null},h.parseArt=function(a){var b;for(b=a.length;b>=0;--b)"string"==typeof a[b]&&(a[b]=PIXI.Texture.fromImage(a[b]));return a},h.parseData=function(a){return a},a.Particle=h}(cloudkid),function(a,b){"use strict";var c=a.ParticleUtils,d=a.Particle,e=PIXI.ParticleContainer,f=function(a,b,c){this._particleConstructor=d,this.particleImages=null,this.startAlpha=1,this.endAlpha=1,this.startSpeed=0,this.endSpeed=0,this.acceleration=null,this.startScale=1,this.endScale=1,this.minimumScaleMultiplier=1,this.startColor=null,this.endColor=null,this.minLifetime=0,this.maxLifetime=0,this.minStartRotation=0,this.maxStartRotation=0,this.minRotationSpeed=0,this.maxRotationSpeed=0,this.particleBlendMode=0,this.customEase=null,this.extraData=null,this.frequency=0,this.maxParticles=1e3,this.emitterLifetime=-1,this.spawnPos=null,this.spawnType=null,this._spawnFunc=null,this.spawnRect=null,this.spawnCircle=null,this.particlesPerWave=1,this.particleSpacing=0,this.angleStart=0,this.rotation=0,this.ownerPos=null,this._prevEmitterPos=null,this._prevPosIsValid=!1,this._posChanged=!1,this._parentIsPC=!1,this._parent=null,this.addAtBack=!1,this.particleCount=0,this._emit=!1,this._spawnTimer=0,this._emitterLife=-1,this._activeParticlesFirst=null,this._activeParticlesLast=null,this._poolFirst=null,this._origConfig=null,this._origArt=null,this.parent=a,b&&c&&this.init(b,c),this.recycle=this.recycle,this.update=this.update,this.rotate=this.rotate,this.updateSpawnPos=this.updateSpawnPos,this.updateOwnerPos=this.updateOwnerPos},g=f.prototype={},h=new PIXI.Point;Object.defineProperty(g,"particleConstructor",{get:function(){return this._particleConstructor},set:function(a){if(a!=this._particleConstructor){this._particleConstructor=a,this.cleanup();for(var b=this._poolFirst;b;b=b.next)b.destroy();this._poolFirst=null,this._origConfig&&this._origArt&&this.init(this._origArt,this._origConfig)}}}),Object.defineProperty(g,"parent",{get:function(){return this._parent},set:function(a){this.cleanup(),this._parent=a,this._parentIsPC=e&&a&&a instanceof e}}),g.init=function(a,b){if(a&&b){this.cleanup(),this._origConfig=b,this._origArt=a,a=Array.isArray(a)?a.slice():[a];var d=this._particleConstructor;this.particleImages=d.parseArt?d.parseArt(a):a,b.alpha?(this.startAlpha=b.alpha.start,this.endAlpha=b.alpha.end):this.startAlpha=this.endAlpha=1,b.speed?(this.startSpeed=b.speed.start,this.endSpeed=b.speed.end):this.startSpeed=this.endSpeed=0;var e=b.acceleration;e&&(e.x||e.y)?(this.endSpeed=this.startSpeed,this.acceleration=new PIXI.Point(e.x,e.y)):this.acceleration=null,b.scale?(this.startScale=b.scale.start,this.endScale=b.scale.end,this.minimumScaleMultiplier=b.scale.minimumScaleMultiplier||1):this.startScale=this.endScale=this.minimumScaleMultiplier=1,b.color&&(this.startColor=c.hexToRGB(b.color.start),b.color.start!=b.color.end?this.endColor=c.hexToRGB(b.color.end):this.endColor=null),b.startRotation?(this.minStartRotation=b.startRotation.min,this.maxStartRotation=b.startRotation.max):this.minStartRotation=this.maxStartRotation=0,b.rotationSpeed?(this.minRotationSpeed=b.rotationSpeed.min,this.maxRotationSpeed=b.rotationSpeed.max):this.minRotationSpeed=this.maxRotationSpeed=0,this.minLifetime=b.lifetime.min,this.maxLifetime=b.lifetime.max,this.particleBlendMode=c.getBlendMode(b.blendMode),b.ease?this.customEase="function"==typeof b.ease?b.ease:c.generateEase(b.ease):this.customEase=null,d.parseData?this.extraData=d.parseData(b.extraData):this.extraData=b.extraData||null,this.spawnRect=this.spawnCircle=null,this.particlesPerWave=1,this.particleSpacing=0,this.angleStart=0;var f;switch(b.spawnType){case"rect":this.spawnType="rect",this._spawnFunc=this._spawnRect;var g=b.spawnRect;this.spawnRect=new PIXI.Rectangle(g.x,g.y,g.w,g.h);break;case"circle":this.spawnType="circle",this._spawnFunc=this._spawnCircle,f=b.spawnCircle,this.spawnCircle=new PIXI.Circle(f.x,f.y,f.r);break;case"ring":this.spawnType="ring",this._spawnFunc=this._spawnRing,f=b.spawnCircle,this.spawnCircle=new PIXI.Circle(f.x,f.y,f.r),this.spawnCircle.minRadius=f.minR;break;case"burst":this.spawnType="burst",this._spawnFunc=this._spawnBurst,this.particlesPerWave=b.particlesPerWave,this.particleSpacing=b.particleSpacing,this.angleStart=b.angleStart?b.angleStart:0;break;case"point":this.spawnType="point",this._spawnFunc=this._spawnPoint;break;default:this.spawnType="point",this._spawnFunc=this._spawnPoint}this.frequency=b.frequency,this.emitterLifetime=b.emitterLifetime||-1,this.maxParticles=b.maxParticles>0?b.maxParticles:1e3,this.addAtBack=!!b.addAtBack,this.rotation=0,this.ownerPos=new PIXI.Point,this.spawnPos=new PIXI.Point(b.pos.x,b.pos.y),this._prevEmitterPos=this.spawnPos.clone(),this._prevPosIsValid=!1,this._spawnTimer=0,this.emit=!0}},g.recycle=function(a){a.next&&(a.next.prev=a.prev),a.prev&&(a.prev.next=a.next),a==this._activeParticlesLast&&(this._activeParticlesLast=a.prev),a==this._activeParticlesFirst&&(this._activeParticlesFirst=a.next),a.prev=null,a.next=this._poolFirst,this._poolFirst=a,this._parentIsPC?(a.alpha=0,a.visible=!1):a.parent&&a.parent.removeChild(a),--this.particleCount},g.rotate=function(a){if(this.rotation!=a){var b=a-this.rotation;this.rotation=a,c.rotatePoint(b,this.spawnPos),this._posChanged=!0}},g.updateSpawnPos=function(a,b){this._posChanged=!0,this.spawnPos.x=a,this.spawnPos.y=b},g.updateOwnerPos=function(a,b){this._posChanged=!0,this.ownerPos.x=a,this.ownerPos.y=b},g.resetPositionTracking=function(){this._prevPosIsValid=!1},Object.defineProperty(g,"emit",{get:function(){return this._emit},set:function(a){this._emit=!!a,this._emitterLife=this.emitterLifetime}}),g.update=function(a){var b,c,d;for(c=this._activeParticlesFirst;c;c=d)d=c.next,c.update(a);var e,f;this._prevPosIsValid&&(e=this._prevEmitterPos.x,f=this._prevEmitterPos.y);var g=this.ownerPos.x+this.spawnPos.x,h=this.ownerPos.y+this.spawnPos.y;if(this.emit)for(this._spawnTimer-=a;this._spawnTimer<=0;){if(this._emitterLife>0&&(this._emitterLife-=this.frequency,this._emitterLife<=0)){this._spawnTimer=0,this._emitterLife=0,this.emit=!1;break}if(this.particleCount>=this.maxParticles)this._spawnTimer+=this.frequency;else{var i;if(i=this.minLifetime==this.maxLifetime?this.minLifetime:Math.random()*(this.maxLifetime-this.minLifetime)+this.minLifetime,-this._spawnTimerb;++b){var n;if(this._poolFirst?(n=this._poolFirst,this._poolFirst=this._poolFirst.next,n.next=null):n=new this.particleConstructor(this),this.particleImages.length>1?n.applyArt(this.particleImages.random()):n.applyArt(this.particleImages[0]),n.startAlpha=this.startAlpha,n.endAlpha=this.endAlpha,n.startSpeed=this.startSpeed,n.endSpeed=this.endSpeed,n.acceleration=this.acceleration,1!=this.minimumScaleMultiplier){var o=Math.random()*(1-this.minimumScaleMultiplier)+this.minimumScaleMultiplier;n.startScale=this.startScale*o,n.endScale=this.endScale*o}else n.startScale=this.startScale,n.endScale=this.endScale;if(n.startColor=this.startColor,n.endColor=this.endColor,this.minRotationSpeed==this.maxRotationSpeed?n.rotationSpeed=this.minRotationSpeed:n.rotationSpeed=Math.random()*(this.maxRotationSpeed-this.minRotationSpeed)+this.minRotationSpeed,n.maxLife=i,n.blendMode=this.particleBlendMode,n.ease=this.customEase,n.extraData=this.extraData,this._spawnFunc(n,j,k,b),n.init(),n.update(-this._spawnTimer),this._parentIsPC&&n.parent){var p=this._parent.children,q=p.indexOf(n);1>q?p.shift():q==p.length-1?p.pop():p.splice(q,1),this.addAtBack?p.unshift(n):p.push(n)}else this.addAtBack?this._parent.addChildAt(n,0):this._parent.addChild(n);this._activeParticlesLast?(this._activeParticlesLast.next=n,n.prev=this._activeParticlesLast,this._activeParticlesLast=n):this._activeParticlesLast=this._activeParticlesFirst=n,++this.particleCount}}this._spawnTimer+=this.frequency}}this._posChanged&&(this._prevEmitterPos.x=g,this._prevEmitterPos.y=h,this._prevPosIsValid=!0,this._posChanged=!1)},g._spawnPoint=function(a,b,c,d){this.minStartRotation==this.maxStartRotation?a.rotation=this.minStartRotation+this.rotation:a.rotation=Math.random()*(this.maxStartRotation-this.minStartRotation)+this.minStartRotation+this.rotation,a.position.x=b,a.position.y=c},g._spawnRect=function(a,b,d,e){this.minStartRotation==this.maxStartRotation?a.rotation=this.minStartRotation+this.rotation:a.rotation=Math.random()*(this.maxStartRotation-this.minStartRotation)+this.minStartRotation+this.rotation,h.x=Math.random()*this.spawnRect.width+this.spawnRect.x,h.y=Math.random()*this.spawnRect.height+this.spawnRect.y,0!==this.rotation&&c.rotatePoint(this.rotation,h),a.position.x=b+h.x,a.position.y=d+h.y},g._spawnCircle=function(a,b,d,e){this.minStartRotation==this.maxStartRotation?a.rotation=this.minStartRotation+this.rotation:a.rotation=Math.random()*(this.maxStartRotation-this.minStartRotation)+this.minStartRotation+this.rotation,h.x=Math.random()*this.spawnCircle.radius,h.y=0,c.rotatePoint(360*Math.random(),h),h.x+=this.spawnCircle.x,h.y+=this.spawnCircle.y,0!==this.rotation&&c.rotatePoint(this.rotation,h),a.position.x=b+h.x,a.position.y=d+h.y},g._spawnRing=function(a,b,d,e){var f=this.spawnCircle;this.minStartRotation==this.maxStartRotation?a.rotation=this.minStartRotation+this.rotation:a.rotation=Math.random()*(this.maxStartRotation-this.minStartRotation)+this.minStartRotation+this.rotation,f.minRadius==f.radius?h.x=Math.random()*(f.radius-f.minRadius)+f.minRadius:h.x=f.radius,h.y=0;var g=360*Math.random();a.rotation+=g,c.rotatePoint(g,h),h.x+=this.spawnCircle.x,h.y+=this.spawnCircle.y,0!==this.rotation&&c.rotatePoint(this.rotation,h),a.position.x=b+h.x,a.position.y=d+h.y},g._spawnBurst=function(a,b,c,d){0===this.particleSpacing?a.rotation=360*Math.random():a.rotation=this.angleStart+this.particleSpacing*d+this.rotation,a.position.x=b,a.position.y=c},g.cleanup=function(){var a,b;for(a=this._activeParticlesFirst;a;a=b)b=a.next,this.recycle(a),a.parent&&a.parent.removeChild(a);this._activeParticlesFirst=this._activeParticlesLast=null,this.particleCount=0},g.destroy=function(){this.cleanup();for(var a=this._poolFirst;a;a=a.next)a.destroy();this._poolFirst=this._parent=this.particleImages=this.spawnPos=this.ownerPos=this.startColor=this.endColor=this.customEase=null},a.Emitter=f}(cloudkid);}(); \ No newline at end of file diff --git a/src/AnimatedParticle.js b/src/AnimatedParticle.js index e7badb6b..dc5fa201 100644 --- a/src/AnimatedParticle.js +++ b/src/AnimatedParticle.js @@ -1,5 +1,6 @@ /** -* @module cloudkid +* @module Animated Particle +* @namespace cloudkid */ (function(cloudkid, undefined) { @@ -11,8 +12,34 @@ var useAPI3 = ParticleUtils.useAPI3; /** - * An individual particle image with an animation. While this class may be functional, it - * has not gotten thorough testing or examples yet, and is not considered to be release ready. + * An individual particle image with an animation. Art data passed to the emitter must be + * formatted in a particular way for AnimatedParticle to be able to handle it: + * + * { + * //framerate is required. It is the animation speed of the particle in frames per + * //second. + * //A value of "matchLife" causes the animation to match the lifetime of an individual + * //particle, instead of at a constant framerate. This causes the animation to play + * //through one time, completing when the particle expires. + * framerate: 6, + * //loop is optional, and defaults to false. + * loop: true, + * //textures is required, and can be an array of any (non-zero) length. + * textures: [ + * //each entry represents a single texture that should be used for one or more + * //frames. Any strings will be converted to Textures with Texture.fromImage(). + * //Instances of PIXI.Texture will be used directly. + * "animFrame1.png", + * //entries can be an object with a 'count' property, telling AnimatedParticle to + * //use that texture for 'count' frames sequentially. + * { + * texture: "animFrame2.png", + * count: 3 + * }, + * "animFrame3.png" + * ] + * } + * * @class AnimatedParticle * @constructor * @param {Emitter} emitter The emitter that controls this AnimatedParticle. @@ -131,6 +158,14 @@ s.destroy.call(this); }; + /** + * Checks over the art that was passed to the Emitter's init() function, to do any special + * modifications to prepare it ahead of time. + * @method parseArt + * @static + * @param {Array} art The array of art data, properly formatted for AnimatedParticle. + * @return {Array} The art, after any needed modifications. + */ AnimatedParticle.parseArt = function(art) { var i, data, output = [], j, textures, tex, outTextures; diff --git a/src/Emitter.js b/src/Emitter.js index dcfd207d..115e0aa5 100644 --- a/src/Emitter.js +++ b/src/Emitter.js @@ -1,5 +1,6 @@ /** -* @module cloudkid +* @module Pixi Particles +* @namespace cloudkid */ (function(cloudkid, undefined) { diff --git a/src/Particle.js b/src/Particle.js index e980134d..ff099aa3 100644 --- a/src/Particle.js +++ b/src/Particle.js @@ -1,5 +1,6 @@ /** -* @module cloudkid +* @module Pixi Particles +* @namespace cloudkid */ (function(cloudkid, undefined) { @@ -406,6 +407,8 @@ /** * Checks over the art that was passed to the Emitter's init() function, to do any special * modifications to prepare it ahead of time. + * @method parseArt + * @static * @param {Array} art The array of art data. For Particle, it should be an array of Textures. * Any strings in the array will be converted to Textures via * Texture.fromImage(). @@ -437,6 +440,19 @@ return art; }; + + /** + * Parses extra emitter data to ensure it is set up for this particle class. + * Particle does nothing to the extra data. + * @method parseData + * @static + * @param {Object} extraData The extra data from the particle config. + * @return {Object} The parsed extra data. + */ + Particle.parseData = function(extraData) + { + return extraData; + }; cloudkid.Particle = Particle; diff --git a/src/ParticleUtils.js b/src/ParticleUtils.js index 4945a29d..13482691 100644 --- a/src/ParticleUtils.js +++ b/src/ParticleUtils.js @@ -1,5 +1,6 @@ /** -* @module cloudkid +* @module Pixi Particles +* @namespace cloudkid */ (function(undefined) { @@ -181,7 +182,8 @@ cloudkid.ParticleUtils = ParticleUtils; /** - * @module global + * @module Pixi Particles + * @namespace window */ /** * Add methods to Array diff --git a/src/PathParticle.js b/src/PathParticle.js index cfc24117..4781f978 100644 --- a/src/PathParticle.js +++ b/src/PathParticle.js @@ -1,5 +1,6 @@ /** -* @module cloudkid +* @module Path Particle +* @namespace cloudkid */ (function(cloudkid, undefined) { @@ -184,6 +185,8 @@ /** * Checks over the art that was passed to the Emitter's init() function, to do any special * modifications to prepare it ahead of time. This just runs Particle.parseArt(). + * @method parseArt + * @static * @param {Array} art The array of art data. For Particle, it should be an array of Textures. * Any strings in the array will be converted to Textures via * Texture.fromImage(). @@ -198,6 +201,8 @@ * Parses extra emitter data to ensure it is set up for this particle class. * PathParticle checks for the existence of path data, and parses the path data for use * by particle instances. + * @method parseData + * @static * @param {Object} extraData The extra data from the particle config. * @return {Object} The parsed extra data. */