Skip to content

Commit 6f5c14b

Browse files
committed
Added drawCurve method to Graphics
1 parent bb526e0 commit 6f5c14b

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

src/engine/renderer/graphics.js

+33-2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,26 @@ game.createClass('Graphics', 'Container', {
9999
this._drawShape(shape);
100100
return this;
101101
},
102+
103+
/**
104+
Draw bezier curve.
105+
@method drawCurve
106+
@param {Curve|Number} sx
107+
@param {Number} sy
108+
@param {Number} ex
109+
@param {Number} ey
110+
@param {Number} h1x
111+
@param {Number} h1y
112+
@param {Number} h2x
113+
@param {Number} h2y
114+
@chainable
115+
**/
116+
drawCurve: function(sx, sy, ex, ey, h1x, h1y, h2x, h2y) {
117+
this.lineWidth = this.lineWidth || 1;
118+
var shape = typeof sx === 'number' ? new game.Curve(sx, sy, ex, ey, h1x, h1y, h2x, h2y) : sx;
119+
this._drawShape(shape, true);
120+
return this;
121+
},
102122

103123
/**
104124
@method drawLine
@@ -325,7 +345,7 @@ game.createClass('GraphicsShape', {
325345

326346
this._renderShape(context);
327347

328-
if (this.fillColor && this.fillAlpha) context.fill();
348+
if (this.fillColor && this.fillAlpha && !this.isLine) context.fill();
329349
if (this.lineWidth) {
330350
context.globalAlpha = this.lineAlpha * alpha;
331351
context.stroke();
@@ -342,7 +362,18 @@ game.createClass('GraphicsShape', {
342362
var x = shape.x * game.scale;
343363
var y = shape.y * game.scale;
344364

345-
if (this.isLine) {
365+
if (this.isLine && shape.start) {
366+
context.moveTo(shape.start.x * game.scale, shape.start.y * game.scale);
367+
context.bezierCurveTo(
368+
shape.handle1.x * game.scale,
369+
shape.handle1.y * game.scale,
370+
shape.handle2.x * game.scale,
371+
shape.handle2.y * game.scale,
372+
shape.end.x * game.scale,
373+
shape.end.y * game.scale
374+
);
375+
}
376+
else if (this.isLine) {
346377
context.moveTo(x, y);
347378
context.lineTo(shape.width, shape.height);
348379
}

0 commit comments

Comments
 (0)