Skip to content

Commit 71f8cc4

Browse files
committed
change CCParticleSystem clone function
1 parent 0ea38ac commit 71f8cc4

File tree

1 file changed

+57
-75
lines changed

1 file changed

+57
-75
lines changed

cocos2d/particle/CCParticleSystem.js

Lines changed: 57 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{
10721072
* @return {cc.Color}
10731073
*/
10741074
getStartColor:function () {
1075-
var color = cc.c4f(this._startColor.r, this._startColor.g, this._startColor.b, this._startColor.a);
1075+
var color = cc.color(this._startColor.r, this._startColor.g, this._startColor.b, this._startColor.a);
10761076
return color;
10771077
},
10781078

@@ -1089,7 +1089,7 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{
10891089
* @return {cc.Color}
10901090
*/
10911091
getStartColorVar:function () {
1092-
var color = cc.c4f(this._startColorVar.r, this._startColorVar.g, this._startColorVar.b, this._startColorVar.a);
1092+
var color = cc.color(this._startColorVar.r, this._startColorVar.g, this._startColorVar.b, this._startColorVar.a);
10931093
return color;
10941094
},
10951095

@@ -1106,7 +1106,7 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{
11061106
* @return {cc.Color}
11071107
*/
11081108
getEndColor:function () {
1109-
var color = cc.c4f(this._endColor.r, this._endColor.g, this._endColor.b, this._endColor.a);
1109+
var color = cc.color(this._endColor.r, this._endColor.g, this._endColor.b, this._endColor.a);
11101110
return color;
11111111
},
11121112

@@ -1123,7 +1123,7 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{
11231123
* @return {cc.Color}
11241124
*/
11251125
getEndColorVar:function () {
1126-
var color = cc.c4f(this._endColorVar.r, this._endColorVar.g, this._endColorVar.b, this._endColorVar.a);
1126+
var color = cc.color(this._endColorVar.r, this._endColorVar.g, this._endColorVar.b, this._endColorVar.a);
11271127
return color;
11281128
},
11291129

@@ -2242,113 +2242,95 @@ cc.ParticleSystem = cc.Node.extend(/** @lends cc.ParticleSystem# */{
22422242
}
22432243
}
22442244
},
2245-
2246-
clone:function () {
2245+
clone:function(){
22472246
var retParticle = new cc.ParticleSystem();
22482247

22492248
// self, not super
2250-
if (retParticle.initWithTotalParticles(this._totalParticles)) {
2249+
if (retParticle.initWithTotalParticles(this.getTotalParticles())) {
22512250
// angle
2252-
retParticle.angle = this.angle;
2253-
retParticle.angleVar = this.angleVar;
2251+
retParticle.setAngle(this.getAngle());
2252+
retParticle.setAngleVar(this.getAngleVar());
22542253

22552254
// duration
2256-
retParticle.duration = this.duration;
2255+
retParticle.setDuration(this.getDuration());
22572256

22582257
// blend function
2259-
retParticle._blendFunc.src = this._blendFunc.src;
2260-
retParticle._blendFunc.dst = this._blendFunc.dst;
2258+
var blend = this.getBlendFunc();
2259+
retParticle.setBlendFunc(blend.src,blend.dst);
22612260

22622261
// color
2263-
var particleStartColor = retParticle._startColor, locStartColor = this._startColor;
2264-
particleStartColor.r = locStartColor.r;
2265-
particleStartColor.g = locStartColor.g;
2266-
particleStartColor.b = locStartColor.b;
2267-
particleStartColor.a = locStartColor.a;
2268-
2269-
var particleStartColorVar = retParticle._startColorVar, locStartColorVar = this._startColorVar;
2270-
particleStartColorVar.r = locStartColorVar.r;
2271-
particleStartColorVar.g = locStartColorVar.g;
2272-
particleStartColorVar.b = locStartColorVar.b;
2273-
particleStartColorVar.a = locStartColorVar.a;
2274-
2275-
var particleEndColor = retParticle._endColor, locEndColor = this._endColor;
2276-
particleEndColor.r = locEndColor.r;
2277-
particleEndColor.g = locEndColor.g;
2278-
particleEndColor.b = locEndColor.b;
2279-
particleEndColor.a = locEndColor.a;
2280-
2281-
var particleEndColorVar = retParticle._endColorVar, locEndColorVar = this._endColorVar;
2282-
particleEndColorVar.r = locEndColorVar.r;
2283-
particleEndColorVar.g = locEndColorVar.g;
2284-
particleEndColorVar.b = locEndColorVar.b;
2285-
particleEndColorVar.a = locEndColorVar.a;
2262+
retParticle.setStartColor(this.getStartColor());
22862263

2287-
// particle size
2288-
retParticle.startSize = this.startSize;
2289-
retParticle.startSizeVar = this.startSizeVar;
2290-
retParticle.endSize = this.endSize;
2291-
retParticle.endSizeVar = this.endSizeVar;
2264+
retParticle.setStartColorVar(this.getStartColorVar());
2265+
2266+
retParticle.setEndColor(this.getEndColor());
2267+
2268+
retParticle.setEndColorVar(this.getEndColorVar());
2269+
2270+
// this size
2271+
retParticle.setStartSize(this.getStartSize());
2272+
retParticle.setStartSizeVar(this.getStartSizeVar());
2273+
retParticle.setEndSize(this.getEndSize());
2274+
retParticle.setEndSizeVar(this.getEndSizeVar());
22922275

22932276
// position
2294-
retParticle.x = this._position.x;
2295-
retParticle.y = this._position.y;
2296-
retParticle._posVar.x = this._posVar.x;
2297-
retParticle._posVar.y = this._posVar.y;
2277+
retParticle.setPosition(cc.p(this.x, this.y));
2278+
retParticle.setPosVar(cc.p(this.getPosVar().x,this.getPosVar().y));
22982279

22992280
// Spinning
2300-
retParticle.startSpin = this.startSpin;
2301-
retParticle.startSpinVar = this.startSpinVar;
2302-
retParticle.endSpin = this.endSpin;
2303-
retParticle.endSpinVar = this.endSpinVar;
2281+
retParticle.setStartSpin(this.getStartSpin()||0);
2282+
retParticle.setStartSpinVar(this.getStartSpinVar()||0);
2283+
retParticle.setEndSpin(this.getEndSpin()||0);
2284+
retParticle.setEndSpinVar(this.getEndSpinVar()||0);
23042285

2305-
retParticle.emitterMode = this.emitterMode;
2286+
retParticle.setEmitterMode(this.getEmitterMode());
23062287

23072288
// Mode A: Gravity + tangential accel + radial accel
2308-
if (this.emitterMode == cc.ParticleSystem.MODE_GRAVITY) {
2309-
var particleModeA = retParticle.modeA, locModeA = this.modeA;
2289+
if (this.getEmitterMode() == cc.ParticleSystem.MODE_GRAVITY) {
23102290
// gravity
2311-
particleModeA.gravity.x = locModeA.gravity.x;
2312-
particleModeA.gravity.y = locModeA.gravity.y;
2291+
var gra = this.getGravity();
2292+
retParticle.setGravity(cc.p(gra.x,gra.y));
23132293

23142294
// speed
2315-
particleModeA.speed = locModeA.speed;
2316-
particleModeA.speedVar = locModeA.speedVar;
2295+
retParticle.setSpeed(this.getSpeed());
2296+
retParticle.setSpeedVar(this.getSpeedVar());
23172297

23182298
// radial acceleration
2319-
particleModeA.radialAccel = locModeA.radialAccel;
2320-
2321-
particleModeA.radialAccelVar = locModeA.radialAccelVar;
2299+
retParticle.setRadialAccel(this.getRadialAccel());
2300+
retParticle.setRadialAccelVar(this.getRadialAccelVar());
23222301

23232302
// tangential acceleration
2324-
particleModeA.tangentialAccel = locModeA.tangentialAccel;
2303+
retParticle.setTangentialAccel(this.getTangentialAccel());
2304+
retParticle.setTangentialAccelVar(this.getTangentialAccelVar());
23252305

2326-
particleModeA.tangentialAccelVar = locModeA.tangentialAccelVar;
2327-
} else if (this.emitterMode == cc.ParticleSystem.MODE_RADIUS) {
2328-
var particleModeB = retParticle.modeB, locModeB = this.modeB;
2306+
} else if (this.getEmitterMode() == cc.ParticleSystem.MODE_RADIUS) {
23292307
// or Mode B: radius movement
2330-
particleModeB.startRadius = locModeB.startRadius;
2331-
particleModeB.startRadiusVar = locModeB.startRadiusVar;
2332-
particleModeB.endRadius = locModeB.endRadius;
2333-
particleModeB.endRadiusVar = locModeB.endRadiusVar;
2334-
particleModeB.rotatePerSecond = locModeB.rotatePerSecond;
2335-
particleModeB.rotatePerSecondVar = locModeB.rotatePerSecondVar;
2308+
retParticle.setStartRadius(this.getStartRadius());
2309+
retParticle.setStartRadiusVar(this.getStartRadiusVar());
2310+
retParticle.setEndRadius(this.getEndRadius());
2311+
retParticle.setEndRadiusVar(this.getEndRadiusVar());
2312+
2313+
retParticle.setRotatePerSecond(this.getRotatePerSecond());
2314+
retParticle.setRotatePerSecondVar(this.getRotatePerSecondVar());
23362315
}
23372316

23382317
// life span
2339-
retParticle.life = this.life;
2340-
retParticle.lifeVar = this.lifeVar;
2318+
retParticle.setLife(this.getLife());
2319+
retParticle.setLifeVar(this.getLifeVar());
23412320

23422321
// emission Rate
2343-
retParticle.emissionRate = this.emissionRate;
2322+
retParticle.setEmissionRate(this.getEmissionRate());
23442323

23452324
//don't get the internal texture if a batchNode is used
2346-
if (!this._batchNode) {
2325+
if (!this.getBatchNode()) {
23472326
// Set a compatible default for the alpha transfer
2348-
retParticle._opacityModifyRGB = this._opacityModifyRGB;
2349-
2327+
retParticle.setOpacityModifyRGB(this.isOpacityModifyRGB());
23502328
// texture
2351-
this.setTextureWithRect(this._texture,this._pointRect);
2329+
var texture = this.getTexture();
2330+
if(texture){
2331+
var size = texture.getContentSize();
2332+
retParticle.setTextureWithRect(texture, cc.rect(0, 0, size.width, size.height));
2333+
}
23522334
}
23532335
}
23542336
return retParticle;

0 commit comments

Comments
 (0)