Skip to content

Commit 93dc67b

Browse files
committed
Graphics.drawArc would fail to draw any subsequent arcs if you set beginFill on it after drawing the first arc.
Graphics.drawArc would only move to the center position of the first arc created and ignore any subsequent arcs. Graphics.drawArc now correctly renders multiple arcs across both WebGL and Canvas. You no longer need to specifically call moveTo to move into the correct place to draw the arc. Graphics.drawArc now bails out if the startAngle = the endAngle and/or the sweep is invalid *before* adjusting any points. Graphics.drawArc now correctly handles the fill on the CanvasRenderer if the arc is a subsequent arc and no line style is set.
1 parent d45a7ba commit 93dc67b

2 files changed

Lines changed: 30 additions & 29 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ We've rolled our own fixes into our version of Pixi, ensuring we keep it as bug-
238238
* Text.lineSpacing is no longer applied to the first line of Text, which prevents text from being cut off further down the Text object.
239239
* If you paused a Sound object that is using audio markers and then resumed it, it wouldn't correctly calculate the resume duration - causing the sound to sometimes play into the marker that followed it (thanks @AnderbergE #1669)
240240
* Animation.play wouldn't correctly set the play state on the Game Objects AnimationManager causing the animation to fail to start (calling AnimationManager.play did work however), now they're both consistently working.
241+
* Graphics.drawArc would fail to draw any subsequent arcs if you set `beginFill` on it after drawing the first arc.
242+
* Graphics.drawArc would only move to the center position of the first arc created and ignore any subsequent arcs.
243+
* Graphics.drawArc now correctly renders multiple arcs across both WebGL and Canvas. You no longer need to specifically call moveTo to move into the correct place to draw the arc.
244+
* Graphics.drawArc now bails out if the startAngle = the endAngle and/or the sweep is invalid *before* adjusting any points.
245+
* Graphics.drawArc now correctly handles the fill on the CanvasRenderer if the arc is a subsequent arc and no line style is set.
241246

242247
### Pixi 2.2.8 Bug Fixes
243248

src/pixi/primitives/Graphics.js

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ PIXI.Graphics.prototype.lineStyle = function(lineWidth, color, alpha)
149149
{
150150
this.lineWidth = lineWidth || 0;
151151
this.lineColor = color || 0;
152-
this.lineAlpha = (arguments.length < 3) ? 1 : alpha;
152+
this.lineAlpha = (alpha === undefined) ? 1 : alpha;
153153

154154
if (this.currentPath)
155155
{
@@ -402,34 +402,13 @@ PIXI.Graphics.prototype.arcTo = function(x1, y1, x2, y2, radius)
402402
*/
403403
PIXI.Graphics.prototype.arc = function(cx, cy, radius, startAngle, endAngle, anticlockwise)
404404
{
405-
var startX = cx + Math.cos(startAngle) * radius;
406-
var startY = cy + Math.sin(startAngle) * radius;
407-
var points;
408-
409-
if (this.currentPath)
410-
{
411-
points = this.currentPath.shape.points;
412-
413-
if (points.length === 0)
414-
{
415-
points.push(startX, startY);
416-
}
417-
else if (points[points.length-2] !== startX || points[points.length-1] !== startY)
418-
{
419-
points.push(startX, startY);
420-
}
421-
}
422-
else
423-
{
424-
this.moveTo(startX, startY);
425-
points = this.currentPath.shape.points;
426-
}
427-
428405
if (startAngle === endAngle)
429406
{
430407
return this;
431408
}
432409

410+
if (typeof anticlockwise === 'undefined') { anticlockwise = false; }
411+
433412
if (!anticlockwise && endAngle <= startAngle)
434413
{
435414
endAngle += Math.PI * 2;
@@ -439,14 +418,30 @@ PIXI.Graphics.prototype.arc = function(cx, cy, radius, startAngle, endAngle, ant
439418
startAngle += Math.PI * 2;
440419
}
441420

442-
var sweep = anticlockwise ? (startAngle - endAngle) *-1 : (endAngle - startAngle);
443-
var segs = Math.ceil( Math.abs(sweep)/ (Math.PI * 2) ) * 40;
421+
var sweep = anticlockwise ? (startAngle - endAngle) * -1 : (endAngle - startAngle);
422+
var segs = Math.ceil(Math.abs(sweep) / (Math.PI * 2)) * 40;
444423

445-
if( sweep === 0 )
424+
// Sweep check - moved here because we don't want to do the moveTo below if the arc fails
425+
if (sweep === 0)
446426
{
447427
return this;
448428
}
449429

430+
var startX = cx + Math.cos(startAngle) * radius;
431+
var startY = cy + Math.sin(startAngle) * radius;
432+
433+
if (anticlockwise && this.filling)
434+
{
435+
this.moveTo(cx, cy);
436+
}
437+
else
438+
{
439+
this.moveTo(startX, startY);
440+
}
441+
442+
// currentPath will always exist after calling a moveTo
443+
var points = this.currentPath.shape.points;
444+
450445
var theta = sweep / (segs * 2);
451446
var theta2 = theta * 2;
452447

@@ -587,7 +582,7 @@ PIXI.Graphics.prototype.drawEllipse = function(x, y, width, height)
587582
* Draws a polygon using the given path.
588583
*
589584
* @method drawPolygon
590-
* @param path {Array} The path data used to construct the polygon.
585+
* @param path {Array} The path data used to construct the polygon. If you've got a Phaser.Polygon object then pass `polygon.points` here.
591586
* @return {Graphics}
592587
*/
593588
PIXI.Graphics.prototype.drawPolygon = function(path)
@@ -602,7 +597,8 @@ PIXI.Graphics.prototype.drawPolygon = function(path)
602597
// see section 3.2: https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments
603598
points = new Array(arguments.length);
604599

605-
for (var i = 0; i < points.length; ++i) {
600+
for (var i = 0; i < points.length; ++i)
601+
{
606602
points[i] = arguments[i];
607603
}
608604
}

0 commit comments

Comments
 (0)