Skip to content

Commit 9e84c9f

Browse files
committed
Fixed slice method
1 parent 5c554f3 commit 9e84c9f

1 file changed

Lines changed: 34 additions & 3 deletions

File tree

src/gameobjects/graphics/Graphics.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ var Graphics = new Class({
11121112
{
11131113
endAngle = -PI2 - overshoot;
11141114
}
1115-
else if (endAngle > 0)
1115+
else if (endAngle >= 0)
11161116
{
11171117
endAngle = -PI2 + endAngle % PI2 - overshoot;
11181118
}
@@ -1159,13 +1159,44 @@ var Graphics = new Class({
11591159
* @param {number} radius - The radius of the slice.
11601160
* @param {number} startAngle - The start angle of the slice, given in radians.
11611161
* @param {number} endAngle - The end angle of the slice, given in radians.
1162-
* @param {boolean} [anticlockwise=false] - Draw the slice piece anticlockwise or clockwise?
1162+
* @param {boolean} [anticlockwise=false] - Whether the drawing should be anticlockwise or clockwise.
1163+
* @param {number} [overshoot=0] - This value allows you to overshoot the endAngle by this amount. Useful if the arc has a thick stroke and needs to overshoot to join-up cleanly.
11631164
*
11641165
* @return {Phaser.GameObjects.Graphics} This Game Object.
11651166
*/
1166-
slice: function (x, y, radius, startAngle, endAngle, anticlockwise)
1167+
slice: function (x, y, radius, startAngle, endAngle, anticlockwise, overshoot)
11671168
{
11681169
if (anticlockwise === undefined) { anticlockwise = false; }
1170+
if (overshoot === undefined) { overshoot = 0; }
1171+
1172+
var PI2 = Math.PI * 2;
1173+
1174+
if (anticlockwise)
1175+
{
1176+
if (endAngle < -PI2)
1177+
{
1178+
endAngle = -PI2 - overshoot;
1179+
}
1180+
else if (endAngle >= 0)
1181+
{
1182+
endAngle = -PI2 + endAngle % PI2 - overshoot;
1183+
}
1184+
}
1185+
else
1186+
{
1187+
endAngle -= startAngle;
1188+
endAngle += overshoot;
1189+
1190+
if (endAngle > PI2 + overshoot)
1191+
{
1192+
endAngle = PI2 + overshoot;
1193+
1194+
}
1195+
else if (endAngle <= -overshoot)
1196+
{
1197+
endAngle = PI2 + endAngle % PI2 - overshoot;
1198+
}
1199+
}
11691200

11701201
this.commandBuffer.push(Commands.BEGIN_PATH);
11711202

0 commit comments

Comments
 (0)