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.
This commit is contained in:
photonstorm 2015-03-25 13:00:08 +00:00
parent d45a7bae8e
commit 93dc67be71
2 changed files with 30 additions and 29 deletions

View file

@ -238,6 +238,11 @@ We've rolled our own fixes into our version of Pixi, ensuring we keep it as bug-
* Text.lineSpacing is no longer applied to the first line of Text, which prevents text from being cut off further down the Text object.
* 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)
* 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.
* 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.
### Pixi 2.2.8 Bug Fixes

View file

@ -149,7 +149,7 @@ PIXI.Graphics.prototype.lineStyle = function(lineWidth, color, alpha)
{
this.lineWidth = lineWidth || 0;
this.lineColor = color || 0;
this.lineAlpha = (arguments.length < 3) ? 1 : alpha;
this.lineAlpha = (alpha === undefined) ? 1 : alpha;
if (this.currentPath)
{
@ -402,34 +402,13 @@ PIXI.Graphics.prototype.arcTo = function(x1, y1, x2, y2, radius)
*/
PIXI.Graphics.prototype.arc = function(cx, cy, radius, startAngle, endAngle, anticlockwise)
{
var startX = cx + Math.cos(startAngle) * radius;
var startY = cy + Math.sin(startAngle) * radius;
var points;
if (this.currentPath)
{
points = this.currentPath.shape.points;
if (points.length === 0)
{
points.push(startX, startY);
}
else if (points[points.length-2] !== startX || points[points.length-1] !== startY)
{
points.push(startX, startY);
}
}
else
{
this.moveTo(startX, startY);
points = this.currentPath.shape.points;
}
if (startAngle === endAngle)
{
return this;
}
if (typeof anticlockwise === 'undefined') { anticlockwise = false; }
if (!anticlockwise && endAngle <= startAngle)
{
endAngle += Math.PI * 2;
@ -439,14 +418,30 @@ PIXI.Graphics.prototype.arc = function(cx, cy, radius, startAngle, endAngle, ant
startAngle += Math.PI * 2;
}
var sweep = anticlockwise ? (startAngle - endAngle) *-1 : (endAngle - startAngle);
var segs = Math.ceil( Math.abs(sweep)/ (Math.PI * 2) ) * 40;
var sweep = anticlockwise ? (startAngle - endAngle) * -1 : (endAngle - startAngle);
var segs = Math.ceil(Math.abs(sweep) / (Math.PI * 2)) * 40;
if( sweep === 0 )
// Sweep check - moved here because we don't want to do the moveTo below if the arc fails
if (sweep === 0)
{
return this;
}
var startX = cx + Math.cos(startAngle) * radius;
var startY = cy + Math.sin(startAngle) * radius;
if (anticlockwise && this.filling)
{
this.moveTo(cx, cy);
}
else
{
this.moveTo(startX, startY);
}
// currentPath will always exist after calling a moveTo
var points = this.currentPath.shape.points;
var theta = sweep / (segs * 2);
var theta2 = theta * 2;
@ -587,7 +582,7 @@ PIXI.Graphics.prototype.drawEllipse = function(x, y, width, height)
* Draws a polygon using the given path.
*
* @method drawPolygon
* @param path {Array} The path data used to construct the polygon.
* @param path {Array} The path data used to construct the polygon. If you've got a Phaser.Polygon object then pass `polygon.points` here.
* @return {Graphics}
*/
PIXI.Graphics.prototype.drawPolygon = function(path)
@ -602,7 +597,8 @@ PIXI.Graphics.prototype.drawPolygon = function(path)
// see section 3.2: https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments
points = new Array(arguments.length);
for (var i = 0; i < points.length; ++i) {
for (var i = 0; i < points.length; ++i)
{
points[i] = arguments[i];
}
}