Skip to content

Commit 806c9d3

Browse files
committed
Stroke ellipse fixes
- Circumference points should calculate point based on top left of ellipse - Graphics missing Ellipse class - Ellipse stroke not "closed"
1 parent 195ea19 commit 806c9d3

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

v3/src/gameobjects/graphics/Graphics.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var GameObject = require('../GameObject');
77
var GetValue = require('../../utils/object/GetValue');
88
var MATH_CONST = require('../../math/const');
99
var Render = require('./GraphicsRender');
10+
var Ellipse = require('../../geom/ellipse/');
1011

1112
var Graphics = new Class({
1213

@@ -375,6 +376,9 @@ var Graphics = new Class({
375376

376377
var points = ellipse.getPoints(smoothness);
377378

379+
// Duplicate the first point to "close" the ellipse stroke
380+
points.push(points[0]);
381+
378382
return this.strokePoints(points);
379383
},
380384

@@ -457,9 +461,9 @@ var Graphics = new Class({
457461
return this;
458462
},
459463

460-
// If key is a string it'll generate a new texture using it and add it into the
464+
// If key is a string it'll generate a new texture using it and add it into the
461465
// Texture Manager (assuming no key conflict happens).
462-
//
466+
//
463467
// If key is a Canvas it will draw the texture to that canvas context. Note that it will NOT
464468
// automatically upload it to the GPU in WebGL mode.
465469

@@ -469,7 +473,7 @@ var Graphics = new Class({
469473

470474
if (width === undefined) { width = sys.game.config.width; }
471475
if (height === undefined) { height = sys.game.config.height; }
472-
476+
473477
Graphics.TargetCamera.setViewport(0, 0, width, height);
474478
Graphics.TargetCamera.scrollX = this.x;
475479
Graphics.TargetCamera.scrollY = this.y;

v3/src/geom/ellipse/CircumferencePoint.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ var CircumferencePoint = function (ellipse, angle, out)
1717
{
1818
if (out === undefined) { out = new Point(); }
1919

20-
var a = ellipse.width / 2;
21-
var b = ellipse.height / 2;
20+
var halfWidth = ellipse.width / 2;
21+
var halfHeight = ellipse.height / 2;
2222

23-
out.x = ellipse.x + a * Math.cos(angle);
24-
out.y = ellipse.y + b * Math.sin(angle);
23+
out.x = ellipse.x + halfWidth + halfWidth * Math.cos(angle);
24+
out.y = ellipse.y + halfHeight + halfHeight * Math.sin(angle);
2525

2626
return out;
2727
};

0 commit comments

Comments
 (0)