Jump to content

Line segments with CanvasRenderingContext2d


JToaster
 Share

Recommended Posts

Hello all. I've been trying to create a simple line drawing 'game' using a bitmapData object and the CanvasRenderingContext2d object it contains. I've been successful, but it wouldn't support drawing two seperate line segments, preferring instead to make a line from the endpoint of the last line to the starting place of the new one. I wrote up some new code to try to fix that, (and I am probably missing something very obvious) but it does not work. No error is thrown, but nothing shows up onscreen. 



update: function()
{

if(this.game.input.activePointer.isDown && !this.game.scale.incorrectOrientation)
{
if(!this.hasMoved)
{
this.ctx.moveTo(this.game.input.activePointer.x,this.game.input.activePointer.y);
this.hasMoved=true;
}
else
{
this.ctx.lineTo(this.game.input.activePointer.x,this.game.input.activePointer.y);
this.ctx.stroke();
}
}

if(this.game.input.activePointer.justReleased)
this.hasMoved=false;
}

Link to comment
Share on other sites

You're method seems right, I used the same way with moveTo and lineTo. The biggest problem came from simple error.

From what I've tried I've had the issue of nothing getting drawn when exporting to Cocoonjs. It was in fact a typo in the stroke style which worked on browser but not on Cocoonjs. So maybe check is the stroke style etc are really applied.

Then you may want to use this.ctx.clear() at the beginning of your function, I know it fixed issues for me.

Otherwise, I'm not shocked by your piece of code, maybe it comes from elsewhere.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...