javascript - Html 5 canvas avoid fill behaviour on overlap - Stack Overflow

As you can see in the picture above I have visible lines between my isometric squares, this is caused by

As you can see in the picture above I have visible lines between my isometric squares, this is caused by each square sligthly overlapping each other. Now the overlapping is unavoidable due to the coordinate system i use to draw with (And I don't want to change it).

This is the code im using to draw the squares

cRenderContext.beginPath();

cRenderContext.moveTo(iPosX, iPosY);
cRenderContext.lineTo(iPosX + iTileWidthIncrement, iPosY - iTileHeightIncrement);
cRenderContext.lineTo(iPosX + iTileWidth, iPosY);
cRenderContext.lineTo(iPosX + iTileWidthIncrement, iPosY + iTileHeightIncrement);
cRenderContext.lineTo(iPosX, iPosY);

cRenderContext.fillStyle = "rgba(1, 0, 1, 1)";
cRenderContext.fill();
cRenderContext.closePath();

What I want to achieve is to draw the squares with out any visible outlines, so basically is there a way to stop fill doing what it currently is on overlap?

EDIT: I will mention each square is drawn with a slightly different color so I can't just fill the whole area with one color and be done (it just looks all black but each color differs by 1 in either the red or blue channel)

As you can see in the picture above I have visible lines between my isometric squares, this is caused by each square sligthly overlapping each other. Now the overlapping is unavoidable due to the coordinate system i use to draw with (And I don't want to change it).

This is the code im using to draw the squares

cRenderContext.beginPath();

cRenderContext.moveTo(iPosX, iPosY);
cRenderContext.lineTo(iPosX + iTileWidthIncrement, iPosY - iTileHeightIncrement);
cRenderContext.lineTo(iPosX + iTileWidth, iPosY);
cRenderContext.lineTo(iPosX + iTileWidthIncrement, iPosY + iTileHeightIncrement);
cRenderContext.lineTo(iPosX, iPosY);

cRenderContext.fillStyle = "rgba(1, 0, 1, 1)";
cRenderContext.fill();
cRenderContext.closePath();

What I want to achieve is to draw the squares with out any visible outlines, so basically is there a way to stop fill doing what it currently is on overlap?

EDIT: I will mention each square is drawn with a slightly different color so I can't just fill the whole area with one color and be done (it just looks all black but each color differs by 1 in either the red or blue channel)

Share Improve this question edited Aug 10, 2011 at 21:50 Tristan asked Aug 10, 2011 at 21:21 TristanTristan 3,8855 gold badges37 silver badges58 bronze badges 4
  • Without outlines it's just one big black canvas though, right? – James Commented Aug 10, 2011 at 21:46
  • yes essentially in the actual code (and the picture) the color of each square is slightly different, with the rgb value incrementing by 1 in either the red or the blue channels – Tristan Commented Aug 10, 2011 at 21:48
  • Do you really mean "overlap"? The edges of each isometric square aren't touching, right? You want to close the gap between them? – James Commented Aug 10, 2011 at 21:53
  • Yeah each square actually over laps other squares there is no gap between them, and this is what i don't understand why am i getting an edge? – Tristan Commented Aug 10, 2011 at 22:13
Add a ment  | 

1 Answer 1

Reset to default 8

Compare this:

http://jsfiddle/HmVtz/

With this:

http://jsfiddle/HmVtz/1/

See the difference?

The difference in the code is that I'm drawing on a half pixel instead of a pixel. Canvas is weird like that. Read up on anti-aliasing/subpixel rendering sometime.

For a simple explanation of why this is, see the Ask Professor Markup here.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745144931a4613603.html

相关推荐

  • javascript - Html 5 canvas avoid fill behaviour on overlap - Stack Overflow

    As you can see in the picture above I have visible lines between my isometric squares, this is caused by

    2小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信