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

graphics.moveTo doesn't work in this situation #144

Open
PeterKop opened this issue Dec 25, 2015 · 3 comments
Open

graphics.moveTo doesn't work in this situation #144

PeterKop opened this issue Dec 25, 2015 · 3 comments

Comments

@PeterKop
Copy link

Hi, when i'm trying to draw a line by mouse, i code like this:

_s = new Shape();
_s.graphics.lineStyle(1, 0x00ff00);
addChild(_s);
stage.addEventListener(TouchEvent.TOUCH, onTouch);

private function onTouch(e:TouchEvent):void {
var touch:Touch = e.getTouch(stage);
if(touch) {
switch(touch.phase) {
case TouchPhase.BEGAN:
_s.graphics.moveTo(touch.globalX, touch.globalY);
break;
case TouchPhase.MOVED:
_s.graphics.lineTo(touch.globalX, touch.globalY);
break;
}
}
}

but i found _s.graphics.moveTo(touch.globalX, touch.globalY); doesn't work, when i press down mouse expect the first time. and the lines will link together.
is there anything wrong with my code?

@PeterKop
Copy link
Author

and i tried flash.display.Shape, that's OK.

@IonSwitz
Copy link
Member

I think your code is ok, I will check on this

@IonSwitz
Copy link
Member

Yes, there is indeed a bug here. The reason is an optimization that can be done when a Stroke is being incremented after being rendered, as it is in your case. (the entire underlying geometry doesn't have to be regenerated). The optimization breaks when the last entry in the underlying geometry is a "moveTo", it seems.

The quick solution in this case is to do this in your example:

case TouchPhase.BEGAN:
_s.graphics.moveTo(touch.globalX, touch.globalY);
_s.graphics.lineTo(touch.globalX, touch.globalY); // ADD THIS TO FIX PROBLEM
break;
case TouchPhase.MOVED:
_s.graphics.lineTo(touch.globalX, touch.globalY);
break;

it creates an increment of 2 entries in the TouchPhase.BEGAN phase, and that removes the problem,

The optimization is significant for very long Strokes, so I don't want to remove it, but I will try to find a way to solve this problem.

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

No branches or pull requests

2 participants