A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Tween animating - using lineTo()

  1. #1
    Senior Member
    Join Date
    Feb 2006
    Location
    Portland OR
    Posts
    138

    Tween animating - using lineTo()

    I have a series of dots on the screen and would simply like to draw a line between the dots sequentially and have the line animate over time from one dot to the other.

    I'm using the lineTo and moveTo methods but that simply draws the image out entirely on publish rather than line segment by line segment. any suggestions would be great.

    I have this working to simply draw the line but am thinking that setting up an array of points for the dots and using the if/else statement here to check when those dot coordinates are reached would be best... any input would be sweet.


    PHP Code:
    var drawLayer:Sprite = new Sprite();
    addChild(drawLayer);

    var 
    xspeed:uint
    var 
    yspeed:uint
    var 
    i:uint 0;


    drawLayer.graphics.lineStyle(00x0000001false"normal"nullnull0);
    drawLayer.graphics.moveTo(1020);

    addEventListener(Event.ENTER_FRAMErunEvent);

    function 
    runEvent(e:Event){
        if (
    10 ){
        
    i++;
        
    xspeed += 8;
        
    yspeed += 8;
        
    drawLayer.graphics.lineTo(xspeedyspeed);
        }
        else{
            
    removeEventListener(Event.ENTER_FRAMErunEvent);
            }
        
        } 
    It would be awesome if I could use something similar to the caurina tweener class and listen for the onComplete Event to start the next segment rather than a big long procedural if/else/or/&& type of scenario... uggh
    Last edited by knottyDJ; 12-18-2008 at 04:34 PM.

  2. #2
    Senior Member
    Join Date
    Feb 2006
    Location
    Portland OR
    Posts
    138
    pushing this back up in the hopes that someone has had some experience animating the drawing of lines via the lineTo method and is willing to offer up a suggestion

  3. #3
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    There are a lot of ways to do it but none of them are really simple/automatic...the first question is whether you want each segment to draw in a set amount of time or at a set speed (eg. is it a problem if a 200px line and a 100px line both draw in 1 second)?

  4. #4
    Senior Member
    Join Date
    Feb 2006
    Location
    Portland OR
    Posts
    138
    Thanks. Yeah, I've resorted to simply having a shape in the library and positioning it then tweening its scaleX property, but that's not quite there either... but waaaay closer. The challenge is calculating the position of the next line segment based on a % scale width of the previous line segment and making sure they connect smoothly - oh and there's rotation angles in there too and my algebra/trig ain't all that.

    Essentially what I am trying to achieve is a gracefully animated graph showing peaks and valleys based on "potentially variable data". and would like that graph to transition/animate in by drawing each point sequentially.

    So lets say i have 3 dots and tweening from one to other can all use the same duration or speed

    dot1.x = 100;
    dot1.y = 50;

    dot2.x = 200;
    dot2.y = 150;

    dot3.x = 400;
    dot3.y = 50;




    // I'm thinking the lineTo would be something like:

    ...{
    xspeed += 8;
    yspeed += 8;

    drawLayer.graphics.lineTo(dot1.x+xspeed, dot1.y+yspeed);
    // or
    //drawLayer.graphics.lineTo((dot1.x+xspeed)+(dot2.x -dot1.x), (dot1.y+yspeed)+(dot2.y -dot1.y));
    }...
    Last edited by knottyDJ; 12-19-2008 at 08:39 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center