Open PeterKop opened 8 years ago
and i tried flash.display.Shape, that's OK.
I think your code is ok, I will check on this
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.
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?