Skip to content

Commit

Permalink
PathParticle gracefully handles broken paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewstart committed Dec 14, 2014
1 parent 253d965 commit 23902ec
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
28 changes: 20 additions & 8 deletions dist/pixi-particles.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,9 +604,10 @@
* the particle.
*
* Some example paths:
* sin(x/10) * 20 : A sine wave path.
* cos(x/100) * 30 : Particles curve counterclockwise (for medium speed/low lifetime particles)
* pow(x/10, 2) / 2 : Particles curve clockwise (remember, +y is down).
*
* "sin(x/10) * 20" // A sine wave path.
* "cos(x/100) * 30" // Particles curve counterclockwise (for medium speed/low lifetime particles)
* "pow(x/10, 2) / 2" // Particles curve clockwise (remember, +y is down).
*
* @class PathParticle
* @constructor
Expand Down Expand Up @@ -662,22 +663,33 @@
this.initialRotation = this.rotation;
//standard init
this.Particle_init();
//cancel the normal movement behavior
this._doNormalMovement = false;

//set the standard PIXI animationSpeed
if(this.extraData && this.extraData.path)
{
var _sharedExtraData = this.emitter._sharedExtraData;
if(_sharedExtraData.path)
if(_sharedExtraData.path !== undefined)
this.path = _sharedExtraData.path;
else
this.path = _sharedExtraData.path = parsePath(this.extraData.path);
{
try
{
this.path = _sharedExtraData.path = parsePath(this.extraData.path);
}
catch(e)
{
console.error("PathParticle: error in parsing path expression");
this.path = _sharedExtraData.path = null;
}
}
}
else
{
console.error("PathParticle requires a path string in extraData!");
this.path = null;
}
//cancel the normal movement behavior
this._doNormalMovement = !this.path;
//reset movement
this.movement = 0;
//grab position
Expand Down Expand Up @@ -750,7 +762,7 @@
{
var lerp = this.Particle_update(delta);
//if the particle died during the update, then don't bother
if(lerp >= 0)
if(lerp >= 0 && this.path)
{
//increase linear movement based on speed
var speed = (this.endSpeed - this.startSpeed) * lerp + this.startSpeed;
Expand Down
Loading

0 comments on commit 23902ec

Please sign in to comment.