Skip to content

Commit c2f25b3

Browse files
authored
Merge pull request phaserjs#3240 from Twilrom/arc-fix
Update WebGL Graphics.arc to work more like on Canvas
2 parents 6e92ff6 + d443ff3 commit c2f25b3

2 files changed

Lines changed: 38 additions & 26 deletions

File tree

src/gameobjects/graphics/Graphics.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ var Graphics = new Class({
350350
{
351351
this.beginPath();
352352
this.arc(x, y, radius, 0, MATH_CONST.PI2);
353-
this.closePath();
354353
this.fillPath();
355354

356355
return this;
@@ -372,7 +371,6 @@ var Graphics = new Class({
372371
{
373372
this.beginPath();
374373
this.arc(x, y, radius, 0, MATH_CONST.PI2);
375-
this.closePath();
376374
this.strokePath();
377375

378376
return this;
@@ -454,25 +452,21 @@ var Graphics = new Class({
454452
this.moveTo(x, y);
455453
this.lineTo(x, y + height);
456454
this.strokePath();
457-
this.closePath();
458455

459456
this.beginPath();
460457
this.moveTo(x + width, y);
461458
this.lineTo(x + width, y + height);
462459
this.strokePath();
463-
this.closePath();
464460

465461
this.beginPath();
466462
this.moveTo(minx, y);
467463
this.lineTo(maxx + width, y);
468464
this.strokePath();
469-
this.closePath();
470465

471466
this.beginPath();
472467
this.moveTo(minx, y + height);
473468
this.lineTo(maxx + width, y + height);
474469
this.strokePath();
475-
this.closePath();
476470

477471
return this;
478472
},

src/renderer/webgl/pipelines/FlatTintPipeline.js

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ var FlatTintPipeline = new Class({
734734
var path = null;
735735
var sin = Math.sin;
736736
var cos = Math.cos;
737+
var PI2 = Math.PI * 2;
737738
var sr = sin(srcRotation);
738739
var cr = cos(srcRotation);
739740
var sra = cr * srcScaleX;
@@ -775,31 +776,51 @@ var FlatTintPipeline = new Class({
775776
endAngle = commands[cmdIndex + 5];
776777
anticlockwise = commands[cmdIndex + 6];
777778

779+
if (lastPath === null)
780+
{
781+
lastPath = new Path(x + cos(startAngle) * radius, y + sin(startAngle) * radius, lineWidth, lineColor, lineAlpha);
782+
pathArray.push(lastPath);
783+
iteration += iterStep;
784+
}
785+
786+
endAngle -= startAngle;
778787
if (anticlockwise)
779788
{
780-
ta = endAngle;
781-
endAngle = startAngle;
782-
startAngle = -ta;
789+
if (endAngle < -PI2)
790+
{
791+
endAngle = -PI2;
792+
}
793+
else if (endAngle > 0)
794+
{
795+
endAngle = -PI2 + endAngle % PI2;
796+
}
797+
}
798+
else if (endAngle > PI2)
799+
{
800+
endAngle = PI2;
783801
}
784-
802+
else if (endAngle < 0)
803+
{
804+
endAngle = PI2 + endAngle % PI2;
805+
}
806+
785807
while (iteration < 1)
786808
{
787-
ta = (endAngle - startAngle) * iteration + startAngle;
809+
ta = endAngle * iteration + startAngle;
788810
tx = x + cos(ta) * radius;
789811
ty = y + sin(ta) * radius;
790812

791-
if (iteration === 0)
792-
{
793-
lastPath = new Path(tx, ty, lineWidth, lineColor, lineAlpha);
794-
pathArray.push(lastPath);
795-
}
796-
else
797-
{
798-
lastPath.points.push(new Point(tx, ty, lineWidth, lineColor, lineAlpha));
799-
}
813+
lastPath.points.push(new Point(tx, ty, lineWidth, lineColor, lineAlpha));
800814

801815
iteration += iterStep;
802816
}
817+
818+
ta = endAngle + startAngle;
819+
tx = x + cos(ta) * radius;
820+
ty = y + sin(ta) * radius;
821+
822+
lastPath.points.push(new Point(tx, ty, lineWidth, lineColor, lineAlpha));
823+
803824
cmdIndex += 6;
804825
break;
805826

@@ -818,16 +839,13 @@ var FlatTintPipeline = new Class({
818839

819840
case Commands.BEGIN_PATH:
820841
pathArray.length = 0;
842+
lastPath = null;
821843
break;
822844

823845
case Commands.CLOSE_PATH:
824-
if (lastPath !== null && lastPath.points.length > 0)
846+
if (lastPath && lastPath.points.length)
825847
{
826-
var firstPoint = lastPath.points[0];
827-
var lastPoint = lastPath.points[lastPath.points.length - 1];
828-
lastPath.points.push(firstPoint);
829-
lastPath = new Path(lastPoint.x, lastPoint.y, lastPoint.width, lastPoint.rgb, lastPoint.alpha);
830-
pathArray.push(lastPath);
848+
lastPath.points.push(lastPath.points[0]);
831849
}
832850
break;
833851

0 commit comments

Comments
 (0)