Skip to content

Commit f57cc5b

Browse files
committed
fixed cocos2d#1354 modify code for ParticleSystem
1 parent 65a54ab commit f57cc5b

File tree

4 files changed

+30
-62
lines changed

4 files changed

+30
-62
lines changed

cocos2d/CCDrawingPrimitives.js

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -427,24 +427,15 @@ cc.DrawingPrimitiveCanvas = cc.DrawingPrimitive.extend(/** @lends cc.DrawingPrim
427427
/**
428428
* draw a star
429429
* @param {CanvasContext} ctx canvas context
430-
* @param {cc.Point} center
431430
* @param {Number} radius
432431
* @param {cc.Color3B|cc.Color4B|cc.Color4F} color
433432
*/
434-
drawStar:function (ctx, center, radius, color) {
433+
drawStar:function (ctx, radius, color) {
435434
var context = ctx || this._renderContext;
436-
context.save();
437-
context.translate(center.x, -center.y);
438-
439-
//context.rotate(cc.DEGREES_TO_RADIANS(45));
440-
context.rotate(0.7853981633974483);
441-
442-
if (color instanceof cc.Color4F) {
435+
if (color instanceof cc.Color4F)
443436
color = new cc.Color3B(0 | (color.r * 255), 0 | (color.g * 255), 0 | (color.b * 255));
444-
}
445437
var colorStr = "rgba(" + color.r + "," + color.g + "," + color.b;
446438
context.fillStyle = colorStr + ",1)";
447-
448439
var subRadius = radius / 10;
449440

450441
context.beginPath();
@@ -465,44 +456,39 @@ cc.DrawingPrimitiveCanvas = cc.DrawingPrimitive.extend(/** @lends cc.DrawingPrim
465456
var g1 = context.createRadialGradient(0, 0, subRadius, 0, 0, radius);
466457
g1.addColorStop(0, colorStr + ", 1)");
467458
g1.addColorStop(0.3, colorStr + ", 0.8)");
468-
//g1.addColorStop(0.6, colorStr + ", 0.4)");
469459
g1.addColorStop(1.0, colorStr + ", 0.0)");
470460
context.fillStyle = g1;
471461
context.beginPath();
472462
var startAngle_1 = 0;
473-
var endAngle_1 = Math.PI * 2;
463+
var endAngle_1 = cc.PI2;
474464
context.arc(0, 0, radius - subRadius, startAngle_1, endAngle_1, false);
475465
context.closePath();
476466
context.fill();
477-
478-
context.restore();
479467
},
480468

481469
/**
482470
* draw a color ball
483471
* @param {CanvasContext} ctx canvas context
484-
* @param {cc.Point} center
485472
* @param {Number} radius
486473
* @param {cc.Color3B|cc.Color4B|cc.Color4F} color
487474
*/
488-
drawColorBall:function (ctx, center, radius, color) {
475+
drawColorBall:function (ctx, radius, color) {
489476
var context = ctx || this._renderContext;
490-
if (color instanceof cc.Color4F) {
477+
if (color instanceof cc.Color4F)
491478
color = new cc.Color3B(0 | (color.r * 255), 0 | (color.g * 255), 0 | (color.b * 255));
492-
}
493479
var colorStr = "rgba(" + color.r + "," + color.g + "," + color.b;
494480
var subRadius = radius / 10;
495481

496-
var g1 = context.createRadialGradient(center.x, -center.y, subRadius, center.x, -center.y, radius);
482+
var g1 = context.createRadialGradient(0, 0, subRadius, 0, 0, radius);
497483
g1.addColorStop(0, colorStr + ", 1)");
498484
g1.addColorStop(0.3, colorStr + ", 0.8)");
499485
g1.addColorStop(0.6, colorStr + ", 0.4)");
500486
g1.addColorStop(1.0, colorStr + ", 0.0)");
501487
context.fillStyle = g1;
502488
context.beginPath();
503489
var startAngle_1 = 0;
504-
var endAngle_1 = Math.PI * 2;
505-
context.arc(center.x, -center.y, radius, startAngle_1, endAngle_1, false);
490+
var endAngle_1 = cc.PI2;
491+
context.arc(0, 0, radius, startAngle_1, endAngle_1, false);
506492
context.closePath();
507493
context.fill();
508494
},
@@ -517,3 +503,5 @@ cc.DrawingPrimitiveCanvas = cc.DrawingPrimitive.extend(/** @lends cc.DrawingPrim
517503
this._renderContext.fillText(strText, x, -y);
518504
}
519505
});
506+
507+
cc.PI2 = Math.PI * 2;

cocos2d/base_nodes/CCNode.js

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,13 +1169,10 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
11691169
*/
11701170
visit:function (ctx) {
11711171
// quick return if not visible
1172-
if (!this._isVisible) {
1172+
if (!this._isVisible)
11731173
return;
1174-
}
1175-
1176-
var context = ctx || cc.renderContext;
1177-
var i;
11781174

1175+
var context = ctx || cc.renderContext, i;
11791176
if (cc.renderContextType == cc.CANVAS) {
11801177
context.save();
11811178
this.transform(context);
@@ -1184,30 +1181,21 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
11841181
this.sortAllChildren();
11851182
// draw children zOrder < 0
11861183
for (i = 0; i < this._children.length; i++) {
1187-
if (this._children[i] && this._children[i]._zOrder < 0) {
1184+
if (this._children[i] && this._children[i]._zOrder < 0)
11881185
this._children[i].visit(context);
1189-
} else {
1186+
else
11901187
break;
1191-
}
11921188
}
1193-
//if (this._isInDirtyRegion()) {
1194-
// self draw
11951189
this.draw(context);
1196-
//}
1197-
// draw children zOrder >= 0
11981190
if (this._children) {
11991191
for (; i < this._children.length; i++) {
1200-
if (this._children[i] && this._children[i]._zOrder >= 0) {
1192+
if (this._children[i] && this._children[i]._zOrder >= 0)
12011193
this._children[i].visit(context);
1202-
}
12031194
}
12041195
}
1205-
} else {
1206-
//if (this._isInDirtyRegion()) {
1207-
// self draw
1196+
} else
12081197
this.draw(context);
1209-
//}
1210-
}
1198+
12111199
this._orderOfArrival = 0;
12121200
context.restore();
12131201
} else {
@@ -1291,14 +1279,11 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
12911279
}
12921280
}
12931281

1294-
if (this._rotation != 0) {
1295-
//context.rotate(cc.DEGREES_TO_RADIANS(this._rotation));
1282+
if (this._rotation != 0)
12961283
context.rotate(this._rotationRadians);
1297-
}
12981284

1299-
if ((this._scaleX != 1) || (this._scaleY != 1)) {
1285+
if ((this._scaleX != 1) || (this._scaleY != 1))
13001286
context.scale(this._scaleX, this._scaleY);
1301-
}
13021287

13031288
if ((this._skewX != 0) || (this._skewY != 0)) {
13041289
context.transform(1,

cocos2d/particle_nodes/CCParticleSystemQuad.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -476,11 +476,10 @@ cc.ParticleSystemQuad = cc.ParticleSystem.extend(/** @lends cc.ParticleSystemQua
476476
if (cc.renderContextType == cc.CANVAS) {
477477
var context = ctx || cc.renderContext;
478478
context.save();
479-
if (this.isBlendAdditive()) {
479+
if (this.isBlendAdditive())
480480
context.globalCompositeOperation = 'lighter';
481-
} else {
481+
else
482482
context.globalCompositeOperation = 'source-over';
483-
}
484483

485484
for (var i = 0; i < this._particleCount; i++) {
486485
var particle = this._particles[i];
@@ -491,11 +490,9 @@ cc.ParticleSystemQuad = cc.ParticleSystem.extend(/** @lends cc.ParticleSystemQua
491490
var drawTexture = this.getTexture();
492491
if (particle.isChangeColor) {
493492
var cacheTextureForColor = cc.TextureCache.getInstance().getTextureColors(this.getTexture());
494-
if (cacheTextureForColor) {
493+
if (cacheTextureForColor)
495494
drawTexture = cc.generateTintImage(this.getTexture(), cacheTextureForColor, particle.color, this._pointRect);
496-
}
497495
}
498-
499496
context.save();
500497
context.globalAlpha = particle.color.a;
501498
context.translate(0 | particle.drawPos.x, -(0 | particle.drawPos.y));
@@ -507,11 +504,13 @@ cc.ParticleSystemQuad = cc.ParticleSystem.extend(/** @lends cc.ParticleSystemQua
507504
context.save();
508505
context.globalAlpha = particle.color.a;
509506
context.translate(0 | particle.drawPos.x, -(0 | particle.drawPos.y));
507+
510508
if (this._shapeType == cc.PARTICLE_STAR_SHAPE) {
511-
cc.drawingUtil.drawStar(context, cc.p(0, 0), lpx, particle.color);
512-
} else {
513-
cc.drawingUtil.drawColorBall(context, cc.p(0, 0), lpx, particle.color);
514-
}
509+
if(particle.rotation)
510+
context.rotate(cc.DEGREES_TO_RADIANS(particle.rotation));
511+
cc.drawingUtil.drawStar(context, lpx, particle.color);
512+
} else
513+
cc.drawingUtil.drawColorBall(context, lpx, particle.color);
515514
context.restore()
516515
}
517516
}

cocos2d/sprite_nodes/CCSprite.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,7 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{
357357
* @return {cc.Rect}
358358
*/
359359
getTextureRect:function () {
360-
r = this._rect;
361-
return cc.rect(r.origin.x, r.origin.y, r.size.width, r.size.height);
360+
return cc.rect(this._rect.origin.x, this._rect.origin.y, this._rect.size.width, this._rect.size.height);
362361
},
363362

364363
/**
@@ -866,14 +865,11 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{
866865
* @param {CanvasContext} ctx 2d context of canvas
867866
*/
868867
draw:function (ctx) {
869-
//this._super();
870-
871868
//cc.PROFILER_START_CATEGORY(kCCProfilerCategorySprite, "cc.Sprite - draw");
872869
var context = ctx || cc.renderContext;
873870
if (cc.renderContextType == cc.CANVAS) {
874-
if (this._isLighterMode) {
871+
if (this._isLighterMode)
875872
context.globalCompositeOperation = 'lighter';
876-
}
877873

878874
context.globalAlpha = this._opacity / 255;
879875
var mpX = 0, mpY = 0;

0 commit comments

Comments
 (0)