From 5db9af60a82f8a0670d1c00d59cf2bd92ddc4466 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Thu, 1 Jun 2017 09:50:22 +0800 Subject: [PATCH] fix particleSystem error for fireball/issues/4943 --- cocos2d/core/value-types/CCAffineTransform.js | 16 ++++++++++++++++ cocos2d/particle/CCSGParticleSystem.js | 10 +++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/cocos2d/core/value-types/CCAffineTransform.js b/cocos2d/core/value-types/CCAffineTransform.js index 872527b995..27c2c4fdf5 100644 --- a/cocos2d/core/value-types/CCAffineTransform.js +++ b/cocos2d/core/value-types/CCAffineTransform.js @@ -98,6 +98,22 @@ cc.pointApplyAffineTransform = function (point, transOrY, t) { return {x: t.a * x + t.c * y + t.tx, y: t.b * x + t.d * y + t.ty}; }; +cc._pointApplyAffineTransformIn = function (point, transOrY, transOrOut, out) { + var x, y, t; + if (out === undefined) { + t = transOrY; + x = point.x; + y = point.y; + out = transOrOut; + } else { + x = point; + y = transOrY; + t = transOrOut; + } + out.x = t.a * x + t.c * y + t.tx; + out.y = t.b * x + t.d * y + t.ty; +}; + cc._pointApplyAffineTransform = function (x, y, t) { //it will remove. return cc.pointApplyAffineTransform(x, y, t); }; diff --git a/cocos2d/particle/CCSGParticleSystem.js b/cocos2d/particle/CCSGParticleSystem.js index 6832a39ccf..24e1f00f5e 100644 --- a/cocos2d/particle/CCSGParticleSystem.js +++ b/cocos2d/particle/CCSGParticleSystem.js @@ -1673,6 +1673,7 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({ } this._particleIdx = 0; + var worldToNodeTransform = this.getWorldToNodeTransform(); var currentPosition = cc.Particle.TemporaryPoints[0]; if (this.positionType === _ccsg.ParticleSystem.Type.FREE) { cc.pIn(currentPosition, this.convertToWorldSpace(this._pointZeroForParticle)); @@ -1760,9 +1761,12 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({ // var newPos = tpa; if (this.positionType === _ccsg.ParticleSystem.Type.FREE || this.positionType === _ccsg.ParticleSystem.Type.RELATIVE) { - var diff = tpb; - cc.pIn(diff, currentPosition); - cc.pSubIn(diff, selParticle.startPos); + var diff = tpb, localStartPos = tpc; + // current Position convert To Node Space + cc._pointApplyAffineTransformIn(currentPosition, worldToNodeTransform, diff); + // start Position convert To Node Space + cc._pointApplyAffineTransformIn(selParticle.startPos, worldToNodeTransform, localStartPos); + cc.pSubIn(diff, localStartPos); cc.pIn(newPos, selParticle.pos); cc.pSubIn(newPos, diff);