Skip to content

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

Open

Description

@PeterKop

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?

Activity

  1. PeterKop commented on Dec 25, 2015

    @PeterKop
    Author

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

  2. IonSwitz commented on Dec 28, 2015

    @IonSwitz
    Member

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

  3. IonSwitz commented on Dec 28, 2015

    @IonSwitz
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions