Skip to content

Commit 6aa1526

Browse files
committed
Graphics.arc has a new optional argument overshoot. This is a small value that is added onto the end of the endAngle and allows you to extend the arc further than the default 360 degrees. You may wish to do this if you're trying to draw an arc with an especially thick line stroke, to ensure there are no gaps. Fix phaserjs#3798
1 parent a64d747 commit 6aa1526

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ There is a new Game Object Component called `TextureCrop`. It replaces the Textu
104104
* `Tileset.glTexture` is a new property that maps to the WebGL Texture for the Tileset image. It's used internally by the renderer to avoid expensive object look-ups and is set automatically in the `Tileset.setImage` method.
105105
* `Frame.glTexture` is a new property that maps to the WebGL Texture for the Frames Texture Source image. It's used internally by the renderer to avoid expensive object look-ups and is set automatically in the `Frame` constructor.
106106
* `TransformMatrix.e` and `TransformMatrix.f` are two new properties that are an alias for the `tx` and `ty` values.
107+
* `Graphics.arc` has a new optional argument `overshoot`. This is a small value that is added onto the end of the `endAngle` and allows you to extend the arc further than the default 360 degrees. You may wish to do this if you're trying to draw an arc with an especially thick line stroke, to ensure there are no gaps. Fix #3798 (thanks @jjalonso)
107108

108109
### Bug Fixes
109110

src/gameobjects/graphics/Graphics.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,9 @@ var Graphics = new Class({
10791079
* Draw an arc.
10801080
*
10811081
* This method can be used to create circles, or parts of circles.
1082+
*
1083+
* Use the optional `overshoot` argument to allow the arc to extend beyond 360 degrees. This is useful if you're drawing
1084+
* an arc with an especially thick line, as it will allow the arc to fully join-up. Try small values at first, i.e. 0.01.
10821085
*
10831086
* Call {@link Phaser.GameObjects.Graphics#fillPath} or {@link Phaser.GameObjects.Graphics#strokePath} after calling
10841087
* this method to draw the arc.
@@ -1092,11 +1095,44 @@ var Graphics = new Class({
10921095
* @param {number} startAngle - The starting angle, in radians.
10931096
* @param {number} endAngle - The ending angle, in radians.
10941097
* @param {boolean} [anticlockwise=false] - Whether the drawing should be anticlockwise or clockwise.
1098+
* @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.
10951099
*
10961100
* @return {Phaser.GameObjects.Graphics} This Game Object.
10971101
*/
1098-
arc: function (x, y, radius, startAngle, endAngle, anticlockwise)
1102+
arc: function (x, y, radius, startAngle, endAngle, anticlockwise, overshoot)
10991103
{
1104+
if (anticlockwise === undefined) { anticlockwise = false; }
1105+
if (overshoot === undefined) { overshoot = 0; }
1106+
1107+
var PI2 = Math.PI * 2;
1108+
1109+
if (anticlockwise)
1110+
{
1111+
if (endAngle < -PI2)
1112+
{
1113+
endAngle = -PI2 - overshoot;
1114+
}
1115+
else if (endAngle > 0)
1116+
{
1117+
endAngle = -PI2 + endAngle % PI2 - overshoot;
1118+
}
1119+
}
1120+
else
1121+
{
1122+
endAngle -= startAngle;
1123+
endAngle += overshoot;
1124+
1125+
if (endAngle > PI2 + overshoot)
1126+
{
1127+
endAngle = PI2 + overshoot;
1128+
1129+
}
1130+
else if (endAngle < -overshoot)
1131+
{
1132+
endAngle = PI2 + endAngle % PI2 - overshoot;
1133+
}
1134+
}
1135+
11001136
this.commandBuffer.push(
11011137
Commands.ARC,
11021138
x, y, radius, startAngle, endAngle, anticlockwise

0 commit comments

Comments
 (0)