Skip to content

Commit

Permalink
Merge pull request #34 from zevlg/master
Browse files Browse the repository at this point in the history
[add] speed.minimumSpeedMultiplier, for particles speed randomization
  • Loading branch information
andrewstart authored Oct 23, 2016
2 parents b362817 + 9d0d7c5 commit 6003103
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
27 changes: 23 additions & 4 deletions dist/pixi-particles.js
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,15 @@ if(!Array.prototype.random)
* @default 0
*/
this.endSpeed = 0;
/**
* A minimum multiplier for the speed of a particle at both start and
* end. A value between minimumSpeedMultiplier and 1 is randomly generated
* and multiplied with startSpeed and endSpeed to provide the actual
* startSpeed and endSpeed for each particle.
* @property {Number} minimumSpeedMultiplier
* @default 1
*/
this.minimumSpeedMultiplier = 1;
/**
* Acceleration to apply to particles. Using this disables
* any interpolation of particle speed. If the particles do
Expand Down Expand Up @@ -1246,9 +1255,13 @@ if(!Array.prototype.random)
{
this.startSpeed = config.speed.start;
this.endSpeed = config.speed.end;
this.minimumSpeedMultiplier = config.speed.minimumSpeedMultiplier || 1;
}
else
{
this.minimumSpeedMultiplier = 1;
this.startSpeed = this.endSpeed = 0;
}
//set up acceleration
var acceleration = config.acceleration;
if(acceleration && (acceleration.x || acceleration.y))
Expand Down Expand Up @@ -1574,7 +1587,7 @@ if(!Array.prototype.random)
for(var len = Math.min(this.particlesPerWave, this.maxParticles - this.particleCount); i < len; ++i)
{
//create particle
var p;
var p, rand;
if(this._poolFirst)
{
p = this._poolFirst;
Expand All @@ -1600,13 +1613,19 @@ if(!Array.prototype.random)
//set up the start and end values
p.startAlpha = this.startAlpha;
p.endAlpha = this.endAlpha;
p.startSpeed = this.startSpeed;
p.endSpeed = this.endSpeed;
if(this.minimumSpeedMultiplier != 1) {
rand = Math.random() * (1 - this.minimumSpeedMultiplier) + this.minimumSpeedMultiplier;
p.startSpeed = this.startSpeed * rand;
p.endSpeed = this.endSpeed * rand;
} else {
p.startSpeed = this.startSpeed;
p.endSpeed = this.endSpeed;
}
p.acceleration.x = this.acceleration.x;
p.acceleration.y = this.acceleration.y;
if(this.minimumScaleMultiplier != 1)
{
var rand = Math.random() * (1 - this.minimumScaleMultiplier) + this.minimumScaleMultiplier;
rand = Math.random() * (1 - this.minimumScaleMultiplier) + this.minimumScaleMultiplier;
p.startScale = this.startScale * rand;
p.endScale = this.endScale * rand;
}
Expand Down
Loading

0 comments on commit 6003103

Please sign in to comment.