Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for Linecap in graphics #212

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/engine/renderer/graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ game.createClass('Graphics', 'Container', {
@default 0
**/
lineWidth: 0,
/**
@property {String} lineCap
**/
lineCap: 'butt',
/**
@property {String} blendMode
@default source-over
Expand Down Expand Up @@ -119,7 +123,7 @@ game.createClass('Graphics', 'Container', {
this._drawShape(shape, true);
return this;
},

/**
@method drawLine
@param {Number} sx Start x
Expand All @@ -142,7 +146,7 @@ game.createClass('Graphics', 'Container', {
this._drawShape(shape, true);
return this;
},

/**
@method drawPolygon
@param {Array} points List of points.
Expand Down Expand Up @@ -193,7 +197,7 @@ game.createClass('Graphics', 'Container', {
@private
**/
_drawShape: function(shape, isLine) {
var data = new game.GraphicsShape(this.lineWidth, this.lineColor, this.lineAlpha, this.fillColor, this.fillAlpha, shape, isLine);
var data = new game.GraphicsShape(this.lineWidth, this.lineColor, this.lineAlpha, this.fillColor, this.fillAlpha, shape, isLine, this.lineCap);
this.shapes.push(data);
},

Expand Down Expand Up @@ -315,19 +319,24 @@ game.createClass('GraphicsShape', {
@property {Number} lineWidth
**/
lineWidth: 0,
/**
@property {String} lineCap
**/
lineCap: 'butt',
/**
@property {Arc|Circle|Rectangle} shape
**/
shape: null,

staticInit: function(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, shape, isLine) {
staticInit: function(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, shape, isLine, lineCap) {
this.lineWidth = lineWidth;
this.lineColor = lineColor;
this.lineAlpha = lineAlpha;
this.fillColor = fillColor;
this.fillAlpha = fillAlpha;
this.shape = shape;
this.isLine = isLine || this.isLine;
this.lineCap = lineCap || this.lineCap;
},

/**
Expand All @@ -341,6 +350,7 @@ game.createClass('GraphicsShape', {
context.fillStyle = this.fillColor;
context.strokeStyle = this.lineColor;
context.lineWidth = this.lineWidth * game.scale;
context.lineCap = this.lineCap;
context.beginPath();

this._renderShape(context);
Expand All @@ -361,7 +371,7 @@ game.createClass('GraphicsShape', {
var shape = this.shape;
var x = shape.x * game.scale;
var y = shape.y * game.scale;

if (this.isLine && shape.start) {
context.moveTo(shape.start.x * game.scale, shape.start.y * game.scale);
context.bezierCurveTo(
Expand Down