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

This commit is contained in:
Richard Davey 2018-07-06 17:15:46 +01:00
parent a64d747c98
commit 6aa1526ea9
2 changed files with 38 additions and 1 deletions

View file

@ -104,6 +104,7 @@ There is a new Game Object Component called `TextureCrop`. It replaces the Textu
* `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.
* `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.
* `TransformMatrix.e` and `TransformMatrix.f` are two new properties that are an alias for the `tx` and `ty` values.
* `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)
### Bug Fixes

View file

@ -1079,6 +1079,9 @@ var Graphics = new Class({
* Draw an arc.
*
* This method can be used to create circles, or parts of circles.
*
* Use the optional `overshoot` argument to allow the arc to extend beyond 360 degrees. This is useful if you're drawing
* 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.
*
* Call {@link Phaser.GameObjects.Graphics#fillPath} or {@link Phaser.GameObjects.Graphics#strokePath} after calling
* this method to draw the arc.
@ -1092,11 +1095,44 @@ var Graphics = new Class({
* @param {number} startAngle - The starting angle, in radians.
* @param {number} endAngle - The ending angle, in radians.
* @param {boolean} [anticlockwise=false] - Whether the drawing should be anticlockwise or clockwise.
* @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.
*
* @return {Phaser.GameObjects.Graphics} This Game Object.
*/
arc: function (x, y, radius, startAngle, endAngle, anticlockwise)
arc: function (x, y, radius, startAngle, endAngle, anticlockwise, overshoot)
{
if (anticlockwise === undefined) { anticlockwise = false; }
if (overshoot === undefined) { overshoot = 0; }
var PI2 = Math.PI * 2;
if (anticlockwise)
{
if (endAngle < -PI2)
{
endAngle = -PI2 - overshoot;
}
else if (endAngle > 0)
{
endAngle = -PI2 + endAngle % PI2 - overshoot;
}
}
else
{
endAngle -= startAngle;
endAngle += overshoot;
if (endAngle > PI2 + overshoot)
{
endAngle = PI2 + overshoot;
}
else if (endAngle < -overshoot)
{
endAngle = PI2 + endAngle % PI2 - overshoot;
}
}
this.commandBuffer.push(
Commands.ARC,
x, y, radius, startAngle, endAngle, anticlockwise