Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[add] speed.minimumSpeedMultiplier, for particles speed randomization #34

Merged
merged 1 commit into from
Oct 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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