diff --git a/particle/libsrc/bin/particle/particle.d.ts b/particle/libsrc/bin/particle/particle.d.ts index ebbc435f..9de534f2 100644 --- a/particle/libsrc/bin/particle/particle.d.ts +++ b/particle/libsrc/bin/particle/particle.d.ts @@ -293,5 +293,31 @@ declare module particle { initParticle(particle: Particle): void; private static getValue(base, variance); advanceParticle(particle: Particle, dt: number): void; + setEmitterXVariance(emitterXVariance: number): void; + setEmitterYVariance(emitterYVariance: number): void; + setLifespan(lifespan: number): void; + setLifespanVariance(lifespanVariance: number): void; + setStartSize(startSize: number): void; + setStartSizeVariance(startSizeVariance: number): void; + setEndSize(endSize: number): void; + setEndSizeVariance(endSizeVariance: number): void; + setEmitAngle(emitAngle: number): void; + setEmitAngleVariance(emitAngleVariance: number): void; + setStartRotation(startRotation: number): void; + setStartRotationVariance(startRotationVariance: number): void; + setEndRotation(endRotation: number): void; + setEndRotationVariance(endRotationVariance: number): void; + setSpeed(speed: number): void; + setSpeedVariance(speedVariance: number): void; + setGravityX(gravityX: number): void; + setGravityY(gravityY: number): void; + setRadialAcceleration(radialAcceleration: number): void; + setRadialAccelerationVariance(radialAccelerationVariance: number): void; + setTangentialAcceleration(tangentialAcceleration: number): void; + setTangentialAccelerationVariance(tangentialAccelerationVariance: number): void; + setStartAlpha(startAlpha: number): void; + setStartAlphaVariance(startAlphaVariance: number): void; + setEndAlpha(endAlpha: number): void; + setEndAlphaVariance(endAlphaVariance: number): void; } } diff --git a/particle/libsrc/bin/particle/particle.js b/particle/libsrc/bin/particle/particle.js index baf91922..67ef1a05 100644 --- a/particle/libsrc/bin/particle/particle.js +++ b/particle/libsrc/bin/particle/particle.js @@ -619,6 +619,85 @@ var particle; locParticle.rotation += locParticle.rotationDelta * dt * 1000; locParticle.alpha += locParticle.alphaDelta * dt * 1000; }; + //增加设置重力系统参数的方法,方便动态改变参数 + p.setEmitterXVariance = function (emitterXVariance) { + this.emitterXVariance = emitterXVariance; + }; + p.setEmitterYVariance = function (emitterYVariance) { + this.emitterYVariance = emitterYVariance; + }; + p.setLifespan = function (lifespan) { + this.lifespan = lifespan; + }; + p.setLifespanVariance = function (lifespanVariance) { + this.lifespanVariance = lifespanVariance; + }; + p.setStartSize = function (startSize) { + this.startSize = startSize; + }; + p.setStartSizeVariance = function (startSizeVariance) { + this.startSizeVariance = startSizeVariance; + }; + p.setEndSize = function (endSize) { + this.endSize = endSize; + }; + p.setEndSizeVariance = function (endSizeVariance) { + this.endSizeVariance = endSizeVariance; + }; + p.setEmitAngle = function (emitAngle) { + this.emitAngle = emitAngle; + }; + p.setEmitAngleVariance = function (emitAngleVariance) { + this.emitAngleVariance = emitAngleVariance; + }; + p.setStartRotation = function (startRotation) { + this.startRotation = startRotation; + }; + p.setStartRotationVariance = function (startRotationVariance) { + this.startRotationVariance = startRotationVariance; + }; + p.setEndRotation = function (endRotation) { + this.endRotation = endRotation; + }; + p.setEndRotationVariance = function (endRotationVariance) { + this.endRotationVariance = endRotationVariance; + }; + p.setSpeed = function (speed) { + this.speed = speed; + }; + p.setSpeedVariance = function (speedVariance) { + this.speedVariance = speedVariance; + }; + p.setGravityX = function (gravityX) { + this.gravityX = gravityX; + }; + p.setGravityY = function (gravityY) { + this.gravityY = gravityY; + }; + p.setRadialAcceleration = function (radialAcceleration) { + this.radialAcceleration = radialAcceleration; + }; + p.setRadialAccelerationVariance = function (radialAccelerationVariance) { + this.radialAccelerationVariance = radialAccelerationVariance; + }; + p.setTangentialAcceleration = function (tangentialAcceleration) { + this.tangentialAcceleration = tangentialAcceleration; + }; + p.setTangentialAccelerationVariance = function (tangentialAccelerationVariance) { + this.tangentialAccelerationVariance = tangentialAccelerationVariance; + }; + p.setStartAlpha = function (startAlpha) { + this.startAlpha = startAlpha; + }; + p.setStartAlphaVariance = function (startAlphaVariance) { + this.startAlphaVariance = startAlphaVariance; + }; + p.setEndAlpha = function (endAlpha) { + this.endAlpha = endAlpha; + }; + p.setEndAlphaVariance = function (endAlphaVariance) { + this.endAlphaVariance = endAlphaVariance; + }; return GravityParticleSystem; }(particle_1.ParticleSystem)); particle_1.GravityParticleSystem = GravityParticleSystem; diff --git a/particle/libsrc/bin/particle/particle.min.js b/particle/libsrc/bin/particle/particle.min.js index 3ed476df..b0c3f883 100644 --- a/particle/libsrc/bin/particle/particle.min.js +++ b/particle/libsrc/bin/particle/particle.min.js @@ -1 +1 @@ -var particle;!function(t){var e=function(){function t(){this.reset()}var e=(__define,t),i=e.prototype;return i.reset=function(){this.x=0,this.y=0,this.scale=1,this.rotation=0,this.alpha=1,this.currentTime=0,this.totalTime=1e3},t}();t.Particle=e,egret.registerClass(e,"particle.Particle")}(particle||(particle={}));var particle;!function(t){var e=function(e){function i(t,i){e.call(this),this._pool=[],this.frameTime=0,this.particles=[],this._emitterX=0,this._emitterY=0,this.emissionTime=-1,this.maxParticles=200,this.numParticles=0,this.particleClass=null,this.particleMeasureRect=new egret.Rectangle,this.transformForMeasure=new egret.Matrix,this.transformForRender=new egret.Matrix,this.setTransformNodeList=[],this.setAlphaNodeList=[],this.bitmapNodeList=[],this.emissionRate=i,this.texture=t,this.$renderNode=new egret.sys.GroupNode}__extends(i,e);var a=__define,r=i,s=r.prototype;return s.getParticle=function(){var e;return e=this._pool.length?this._pool.pop():this.particleClass?new this.particleClass:new t.Particle},s.removeParticle=function(t){var e=this.particles.indexOf(t);return-1!=e?(t.reset(),this.particles.splice(e,1),this._pool.push(t),this.numParticles--,!0):!1},s.initParticle=function(t){t.x=this.emitterX,t.y=this.emitterY,t.currentTime=0,t.totalTime=1e3},s.updateRelativeBounds=function(t){t?(null==this.relativeContentBounds&&(this.relativeContentBounds=new egret.Rectangle),this.relativeContentBounds.copyFrom(t),this.relativeContentBounds.x+=this.emitterX,this.relativeContentBounds.y+=this.emitterY):this.relativeContentBounds=null,this.mask=this.relativeContentBounds},a(s,"emitterBounds",function(){return this._emitterBounds},function(t){this._emitterBounds=t,this.updateRelativeBounds(t)}),a(s,"emitterX",function(){return this._emitterX},function(t){this._emitterX=t,this.updateRelativeBounds(this.emitterBounds)}),a(s,"emitterY",function(){return this._emitterY},function(t){this._emitterY=t,this.updateRelativeBounds(this.emitterBounds)}),s.start=function(t){void 0===t&&(t=-1),0!=this.emissionRate&&(this.emissionTime=t,egret.Ticker.getInstance().register(this.update,this))},s.stop=function(t){void 0===t&&(t=!1),this.emissionTime=0,t&&(this.clear(),egret.Ticker.getInstance().unregister(this.update,this))},s.update=function(t){if(-1==this.emissionTime||this.emissionTime>0){for(this.frameTime+=t;this.frameTime>0;)this.numParticles0){for(var e,i=this.texture,a=Math.round(i.$getScaleBitmapWidth()),r=Math.round(i.$getScaleBitmapHeight()),s=egret.Rectangle.create(),n=0;ne&&this.numParticles0&&(this.particles.push(t),this.numParticles++)},s.advanceParticle=function(t,e){t.y-=e/6},s.$render=function(){if(this.numParticles>0)for(var t,e=this.texture,i=Math.round(e.$getScaleBitmapWidth()),a=Math.round(e.$getScaleBitmapHeight()),r=e._offsetX,s=e._offsetY,n=e._bitmapX,h=e._bitmapY,o=e._bitmapWidth,c=e._bitmapHeight,l=0;l0?a:0,!(0>=a)){e.x=i.getValue(this.emitterX,this.emitterXVariance),e.y=i.getValue(this.emitterY,this.emitterYVariance),e.startX=this.emitterX,e.startY=this.emitterY;var r=i.getValue(this.emitAngle,this.emitAngleVariance),s=i.getValue(this.speed,this.speedVariance);e.velocityX=s*egret.NumberUtils.cos(r),e.velocityY=s*egret.NumberUtils.sin(r),e.radialAcceleration=i.getValue(this.radialAcceleration,this.radialAccelerationVariance),e.tangentialAcceleration=i.getValue(this.tangentialAcceleration,this.tangentialAccelerationVariance);var n=i.getValue(this.startSize,this.startSizeVariance);.1>n&&(n=.1);var h=i.getValue(this.endSize,this.endSizeVariance);.1>h&&(h=.1);var o=this.texture.textureWidth;e.scale=n/o,e.scaleDelta=(h-n)/a/o;var c=i.getValue(this.startRotation,this.startRotationVariance),l=i.getValue(this.endRotation,this.endRotationVariance);e.rotation=c,e.rotationDelta=(l-c)/a;var m=i.getValue(this.startAlpha,this.startAlphaVariance),d=i.getValue(this.endAlpha,this.endAlphaVariance);e.alpha=m,e.alphaDelta=(d-m)/a}},i.getValue=function(t,e){return t+e*(2*Math.random()-1)},r.advanceParticle=function(t,e){var i=t;e/=1e3;var a=i.totalTime-i.currentTime;e=a>e?e:a,i.currentTime+=e;var r=i.x-i.startX,s=i.y-i.startY,n=Math.sqrt(r*r+s*s);.01>n&&(n=.01);var h=r/n,o=s/n,c=h,l=o;h*=i.radialAcceleration,o*=i.radialAcceleration;var m=c;c=-l*i.tangentialAcceleration,l=m*i.tangentialAcceleration,i.velocityX+=e*(this.gravityX+h+c),i.velocityY+=e*(this.gravityY+o+l),i.x+=i.velocityX*e,i.y+=i.velocityY*e,i.scale+=i.scaleDelta*e*1e3,i.rotation+=i.rotationDelta*e*1e3,i.alpha+=i.alphaDelta*e*1e3},i}(t.ParticleSystem);t.GravityParticleSystem=e,egret.registerClass(e,"particle.GravityParticleSystem")}(particle||(particle={})); \ No newline at end of file +var particle;!function(t){var e=function(){function t(){this.reset()}var e=(__define,t),i=e.prototype;return i.reset=function(){this.x=0,this.y=0,this.scale=1,this.rotation=0,this.alpha=1,this.currentTime=0,this.totalTime=1e3},t}();t.Particle=e,egret.registerClass(e,"particle.Particle")}(particle||(particle={}));var particle;!function(t){var e=function(e){function i(t,i){e.call(this),this._pool=[],this.frameTime=0,this.particles=[],this._emitterX=0,this._emitterY=0,this.emissionTime=-1,this.maxParticles=200,this.numParticles=0,this.particleClass=null,this.particleMeasureRect=new egret.Rectangle,this.transformForMeasure=new egret.Matrix,this.transformForRender=new egret.Matrix,this.setTransformNodeList=[],this.setAlphaNodeList=[],this.bitmapNodeList=[],this.emissionRate=i,this.texture=t,this.$renderNode=new egret.sys.GroupNode}__extends(i,e);var a=__define,r=i,s=r.prototype;return s.getParticle=function(){var e;return e=this._pool.length?this._pool.pop():this.particleClass?new this.particleClass:new t.Particle},s.removeParticle=function(t){var e=this.particles.indexOf(t);return-1!=e?(t.reset(),this.particles.splice(e,1),this._pool.push(t),this.numParticles--,!0):!1},s.initParticle=function(t){t.x=this.emitterX,t.y=this.emitterY,t.currentTime=0,t.totalTime=1e3},s.updateRelativeBounds=function(t){t?(null==this.relativeContentBounds&&(this.relativeContentBounds=new egret.Rectangle),this.relativeContentBounds.copyFrom(t),this.relativeContentBounds.x+=this.emitterX,this.relativeContentBounds.y+=this.emitterY):this.relativeContentBounds=null,this.mask=this.relativeContentBounds},a(s,"emitterBounds",function(){return this._emitterBounds},function(t){this._emitterBounds=t,this.updateRelativeBounds(t)}),a(s,"emitterX",function(){return this._emitterX},function(t){this._emitterX=t,this.updateRelativeBounds(this.emitterBounds)}),a(s,"emitterY",function(){return this._emitterY},function(t){this._emitterY=t,this.updateRelativeBounds(this.emitterBounds)}),s.start=function(t){void 0===t&&(t=-1),0!=this.emissionRate&&(this.emissionTime=t,egret.Ticker.getInstance().register(this.update,this))},s.stop=function(t){void 0===t&&(t=!1),this.emissionTime=0,t&&(this.clear(),egret.Ticker.getInstance().unregister(this.update,this))},s.update=function(t){if(-1==this.emissionTime||this.emissionTime>0){for(this.frameTime+=t;this.frameTime>0;)this.numParticles0){for(var e,i=this.texture,a=Math.round(i.$getScaleBitmapWidth()),r=Math.round(i.$getScaleBitmapHeight()),s=egret.Rectangle.create(),n=0;ne&&this.numParticles0&&(this.particles.push(t),this.numParticles++)},s.advanceParticle=function(t,e){t.y-=e/6},s.$render=function(){if(this.numParticles>0)for(var t,e=this.texture,i=Math.round(e.$getScaleBitmapWidth()),a=Math.round(e.$getScaleBitmapHeight()),r=e._offsetX,s=e._offsetY,n=e._bitmapX,c=e._bitmapY,o=e._bitmapWidth,h=e._bitmapHeight,l=0;l0?a:0,!(0>=a)){e.x=i.getValue(this.emitterX,this.emitterXVariance),e.y=i.getValue(this.emitterY,this.emitterYVariance),e.startX=this.emitterX,e.startY=this.emitterY;var r=i.getValue(this.emitAngle,this.emitAngleVariance),s=i.getValue(this.speed,this.speedVariance);e.velocityX=s*egret.NumberUtils.cos(r),e.velocityY=s*egret.NumberUtils.sin(r),e.radialAcceleration=i.getValue(this.radialAcceleration,this.radialAccelerationVariance),e.tangentialAcceleration=i.getValue(this.tangentialAcceleration,this.tangentialAccelerationVariance);var n=i.getValue(this.startSize,this.startSizeVariance);.1>n&&(n=.1);var c=i.getValue(this.endSize,this.endSizeVariance);.1>c&&(c=.1);var o=this.texture.textureWidth;e.scale=n/o,e.scaleDelta=(c-n)/a/o;var h=i.getValue(this.startRotation,this.startRotationVariance),l=i.getValue(this.endRotation,this.endRotationVariance);e.rotation=h,e.rotationDelta=(l-h)/a;var m=i.getValue(this.startAlpha,this.startAlphaVariance),u=i.getValue(this.endAlpha,this.endAlphaVariance);e.alpha=m,e.alphaDelta=(u-m)/a}},i.getValue=function(t,e){return t+e*(2*Math.random()-1)},r.advanceParticle=function(t,e){var i=t;e/=1e3;var a=i.totalTime-i.currentTime;e=a>e?e:a,i.currentTime+=e;var r=i.x-i.startX,s=i.y-i.startY,n=Math.sqrt(r*r+s*s);.01>n&&(n=.01);var c=r/n,o=s/n,h=c,l=o;c*=i.radialAcceleration,o*=i.radialAcceleration;var m=h;h=-l*i.tangentialAcceleration,l=m*i.tangentialAcceleration,i.velocityX+=e*(this.gravityX+c+h),i.velocityY+=e*(this.gravityY+o+l),i.x+=i.velocityX*e,i.y+=i.velocityY*e,i.scale+=i.scaleDelta*e*1e3,i.rotation+=i.rotationDelta*e*1e3,i.alpha+=i.alphaDelta*e*1e3},r.setEmitterXVariance=function(t){this.emitterXVariance=t},r.setEmitterYVariance=function(t){this.emitterYVariance=t},r.setLifespan=function(t){this.lifespan=t},r.setLifespanVariance=function(t){this.lifespanVariance=t},r.setStartSize=function(t){this.startSize=t},r.setStartSizeVariance=function(t){this.startSizeVariance=t},r.setEndSize=function(t){this.endSize=t},r.setEndSizeVariance=function(t){this.endSizeVariance=t},r.setEmitAngle=function(t){this.emitAngle=t},r.setEmitAngleVariance=function(t){this.emitAngleVariance=t},r.setStartRotation=function(t){this.startRotation=t},r.setStartRotationVariance=function(t){this.startRotationVariance=t},r.setEndRotation=function(t){this.endRotation=t},r.setEndRotationVariance=function(t){this.endRotationVariance=t},r.setSpeed=function(t){this.speed=t},r.setSpeedVariance=function(t){this.speedVariance=t},r.setGravityX=function(t){this.gravityX=t},r.setGravityY=function(t){this.gravityY=t},r.setRadialAcceleration=function(t){this.radialAcceleration=t},r.setRadialAccelerationVariance=function(t){this.radialAccelerationVariance=t},r.setTangentialAcceleration=function(t){this.tangentialAcceleration=t},r.setTangentialAccelerationVariance=function(t){this.tangentialAccelerationVariance=t},r.setStartAlpha=function(t){this.startAlpha=t},r.setStartAlphaVariance=function(t){this.startAlphaVariance=t},r.setEndAlpha=function(t){this.endAlpha=t},r.setEndAlphaVariance=function(t){this.endAlphaVariance=t},i}(t.ParticleSystem);t.GravityParticleSystem=e,egret.registerClass(e,"particle.GravityParticleSystem")}(particle||(particle={})); \ No newline at end of file diff --git a/particle/libsrc/src/GravityParticleSystem.ts b/particle/libsrc/src/GravityParticleSystem.ts index 09335aa4..544b6840 100644 --- a/particle/libsrc/src/GravityParticleSystem.ts +++ b/particle/libsrc/src/GravityParticleSystem.ts @@ -325,5 +325,84 @@ module particle { locParticle.rotation += locParticle.rotationDelta * dt * 1000; locParticle.alpha += locParticle.alphaDelta * dt * 1000; } + //增加设置重力系统参数的方法,方便动态改变参数 + public setEmitterXVariance(emitterXVariance:number) { + this.emitterXVariance = emitterXVariance; + } + public setEmitterYVariance(emitterYVariance:number) { + this.emitterYVariance = emitterYVariance; + } + public setLifespan(lifespan:number) { + this.lifespan = lifespan; + } + public setLifespanVariance(lifespanVariance:number) { + this.lifespanVariance = lifespanVariance; + } + public setStartSize(startSize:number) { + this.startSize = startSize; + } + public setStartSizeVariance(startSizeVariance:number) { + this.startSizeVariance = startSizeVariance; + } + public setEndSize(endSize:number) { + this.endSize = endSize; + } + public setEndSizeVariance(endSizeVariance:number) { + this.endSizeVariance = endSizeVariance; + } + public setEmitAngle(emitAngle:number) { + this.emitAngle = emitAngle; + } + public setEmitAngleVariance(emitAngleVariance:number) { + this.emitAngleVariance = emitAngleVariance; + } + public setStartRotation(startRotation:number) { + this.startRotation = startRotation; + } + public setStartRotationVariance(startRotationVariance:number) { + this.startRotationVariance = startRotationVariance; + } + public setEndRotation(endRotation:number) { + this.endRotation = endRotation; + } + public setEndRotationVariance(endRotationVariance:number) { + this.endRotationVariance = endRotationVariance; + } + public setSpeed(speed:number) { + this.speed = speed; + } + public setSpeedVariance(speedVariance:number) { + this.speedVariance = speedVariance; + } + public setGravityX(gravityX:number) { + this.gravityX = gravityX; + } + public setGravityY(gravityY:number) { + this.gravityY = gravityY; + } + public setRadialAcceleration(radialAcceleration:number) { + this.radialAcceleration = radialAcceleration; + } + public setRadialAccelerationVariance(radialAccelerationVariance:number) { + this.radialAccelerationVariance = radialAccelerationVariance; + } + public setTangentialAcceleration(tangentialAcceleration:number) { + this.tangentialAcceleration = tangentialAcceleration; + } + public setTangentialAccelerationVariance(tangentialAccelerationVariance:number) { + this.tangentialAccelerationVariance = tangentialAccelerationVariance; + } + public setStartAlpha(startAlpha:number) { + this.startAlpha = startAlpha; + } + public setStartAlphaVariance(startAlphaVariance:number) { + this.startAlphaVariance = startAlphaVariance; + } + public setEndAlpha(endAlpha:number) { + this.endAlpha = endAlpha; + } + public setEndAlphaVariance(endAlphaVariance:number) { + this.endAlphaVariance = endAlphaVariance; + } } } \ No newline at end of file