Skip to content

Commit

Permalink
fix canvas draw point error
Browse files Browse the repository at this point in the history
  • Loading branch information
drelaptop committed Apr 12, 2018
1 parent 7eb4663 commit 4b19b78
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
15 changes: 5 additions & 10 deletions cocos2d/core/CCDrawingPrimitivesCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,9 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
if (!size) {
size = 1;
}
var locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
var newPoint = cc.p(point.x * locScaleX, point.y * locScaleY);
var ctx = this._renderContext.getContext();
ctx.beginPath();
ctx.arc(newPoint.x, -newPoint.y, size * locScaleX, 0, Math.PI * 2, false);
ctx.arc(point.x, -point.y, size, 0, Math.PI * 2, false);
ctx.closePath();
ctx.fill();
},
Expand All @@ -79,11 +77,11 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
if (!size) {
size = 1;
}
var locContext = this._renderContext.getContext(),locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
var locContext = this._renderContext.getContext();

locContext.beginPath();
for (var i = 0, len = points.length; i < len; i++)
locContext.arc(points[i].x * locScaleX, -points[i].y * locScaleY, size * locScaleX, 0, Math.PI * 2, false);
locContext.arc(points[i].x, -points[i].y, size, 0, Math.PI * 2, false);
locContext.closePath();
locContext.fill();
},
Expand All @@ -95,7 +93,7 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
* @param {cc.Point} destination
*/
drawLine:function (origin, destination) {
var locContext = this._renderContext.getContext(), locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
var locContext = this._renderContext.getContext();
locContext.beginPath();
locContext.moveTo(origin.x , -origin.y );
locContext.lineTo(destination.x, -destination.y );
Expand Down Expand Up @@ -151,7 +149,6 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
throw new Error("Polygon's point must greater than 2");

var firstPoint = vertices[0], locContext = this._renderContext.getContext();
var locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
locContext.beginPath();
locContext.moveTo(firstPoint.x , -firstPoint.y );
for (var i = 1, len = vertices.length; i < len; i++)
Expand Down Expand Up @@ -189,7 +186,6 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
drawCircle: function (center, radius, angle, segments, drawLineToCenter) {
drawLineToCenter = drawLineToCenter || false;
var locContext = this._renderContext.getContext();
var locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
locContext.beginPath();
var endAngle = angle - Math.PI * 2;
locContext.arc(0 | (center.x ), 0 | -(center.y ), radius , -angle, -endAngle, false);
Expand Down Expand Up @@ -379,7 +375,6 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
drawColorBall:function (ctx, radius, color) {
var wrapper = ctx || this._renderContext;
var context = wrapper.getContext();
radius *= cc.view.getScaleX();
var colorStr = "rgba(" +(0|color.r) + "," + (0|color.g) + "," + (0|color.b);
var subRadius = radius / 10;

Expand Down Expand Up @@ -432,6 +427,6 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
* @param {Number} width
*/
setLineWidth:function (width) {
this._renderContext.getContext().lineWidth = width * cc.view.getScaleX();
this._renderContext.getContext().lineWidth = width;
}
});
5 changes: 2 additions & 3 deletions extensions/spine/CCSkeletonCanvasRenderCmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,12 @@ proto.rendering = function (wrapper, scaleX, scaleY) {
}

// Bone origins.
// FIXME: point position wrong, might due to scale
drawingUtil.setPointSize(4);
var pointSize = 4;
drawingUtil.setDrawColor(0, 0, 255, 255); // Root bone is blue.

for (i = 0, n = locSkeleton.bones.length; i < n; i++) {
bone = locSkeleton.bones[i];
drawingUtil.drawPoint({x: bone.worldX, y: bone.worldY});
drawingUtil.drawPoint({x: bone.worldX, y: bone.worldY}, pointSize);
if (i === 0)
drawingUtil.setDrawColor(0, 255, 0, 255);
}
Expand Down

0 comments on commit 4b19b78

Please sign in to comment.