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

Line draw with dot issue #826

Closed
akamdar opened this issue Dec 14, 2016 · 5 comments
Closed

Line draw with dot issue #826

akamdar opened this issue Dec 14, 2016 · 5 comments
Labels

Comments

@akamdar
Copy link

akamdar commented Dec 14, 2016

line draw

I am using easelJS for drawing on canvas. While drawing a line, it generate multiple dots on the line.

@lannymcnie
Copy link
Member

This looks like you are drawing lineTo commands on mousemove. If your line is partially transparent, this will be the result.

@akamdar
Copy link
Author

akamdar commented Dec 14, 2016

@lannymcnie my code is as below.

 scope.init = function(){
  stage = new createjs.Stage(element[0].id);
  stage.enableDOMEvents(true);
  createjs.Touch.enable(stage);
  shellWrapper = new createjs.Container();
  shellWrapper.id = mainContainerId;
  shellWrapper.hitArea = new createjs.Shape(new createjs.Graphics().f('#000').dr(0,0,cacheWidth,cacheHeight));
  shellWrapper.cache(0,0,cacheWidth,cacheHeight); // Cache it.
  stage.addChild(shellWrapper);
  drawing = new createjs.Shape();
  shellWrapper.addChild(drawing);
  stage.update();
}

scope.mouseDown = function(event) {
  oldX = event.stageX;
  oldY = event.stageY;

  shellWrapper.addEventListener('pressmove', function(evt){

	drawing.graphics.beginStroke(color)
		.setStrokeStyle(size, 'round')
		.moveTo(oldX, oldY)
		.lineTo(evt.stageX, evt.stageY);

	oldX = evt.stageX;
	oldY = evt.stageY;
	shellWrapper.updateCache(erase?'destination-out':'source-over');
	drawing.graphics.clear();
	stage.update();
  });
};

@gskinner
Copy link
Member

By using moveTo, beginStroke, and setStrokeStyle each pressmove, your code is drawing a brand new path each time. With the alpha applied, the overlapping portions of these segments appears darker, which is why you see the dots.

If color and size don't change during a single press, then you should be able to solve this by only calling moveTo, etc on mouse down, and then lineTo on pressmove.

@akamdar
Copy link
Author

akamdar commented Dec 15, 2016

@gskinner size is not static. We have three different options when user select pen/highlighter size. I have tried with your approach but the size remains same. We have two options for draw, 1) Pen and 2) Highlighter. So for highlighter, I am using alpha value (0.3).

drawing.graphics.beginStroke(color)
.setStrokeStyle(size, 'round')
.moveTo(oldX, oldY);

shellWrapper.addEventListener('pressmove', function(evt){
      drawing.graphics.lineTo(evt.stageX, evt.stageY);

@lannymcnie
Copy link
Member

Closing since this is not a bug.

Feel free to reopen with a specific question or bug report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants