Skip to content

Commit

Permalink
Added drawCurve method to Graphics
Browse files Browse the repository at this point in the history
  • Loading branch information
ekelokorpi committed Jan 8, 2019
1 parent bb526e0 commit 6f5c14b
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/engine/renderer/graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,26 @@ game.createClass('Graphics', 'Container', {
this._drawShape(shape);
return this;
},

/**
Draw bezier curve.
@method drawCurve
@param {Curve|Number} sx
@param {Number} sy
@param {Number} ex
@param {Number} ey
@param {Number} h1x
@param {Number} h1y
@param {Number} h2x
@param {Number} h2y
@chainable
**/
drawCurve: function(sx, sy, ex, ey, h1x, h1y, h2x, h2y) {
this.lineWidth = this.lineWidth || 1;
var shape = typeof sx === 'number' ? new game.Curve(sx, sy, ex, ey, h1x, h1y, h2x, h2y) : sx;
this._drawShape(shape, true);
return this;
},

/**
@method drawLine
Expand Down Expand Up @@ -325,7 +345,7 @@ game.createClass('GraphicsShape', {

this._renderShape(context);

if (this.fillColor && this.fillAlpha) context.fill();
if (this.fillColor && this.fillAlpha && !this.isLine) context.fill();
if (this.lineWidth) {
context.globalAlpha = this.lineAlpha * alpha;
context.stroke();
Expand All @@ -342,7 +362,18 @@ game.createClass('GraphicsShape', {
var x = shape.x * game.scale;
var y = shape.y * game.scale;

if (this.isLine) {
if (this.isLine && shape.start) {
context.moveTo(shape.start.x * game.scale, shape.start.y * game.scale);
context.bezierCurveTo(
shape.handle1.x * game.scale,
shape.handle1.y * game.scale,
shape.handle2.x * game.scale,
shape.handle2.y * game.scale,
shape.end.x * game.scale,
shape.end.y * game.scale
);
}
else if (this.isLine) {
context.moveTo(x, y);
context.lineTo(shape.width, shape.height);
}
Expand Down

0 comments on commit 6f5c14b

Please sign in to comment.