Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
dwightepp

LinePath2D

Recommended Posts

I've followed these instructions (minus the multiple squares)

http://www.greensock.com/asdocs/com/greensock/motionPaths/LinePath2D.html

and have a movieclip following a path I define.  I can't seem to figure out how to when that tween is completed how to get it to tween along a new path again?  I can send it a new path to follow but it just duplicates the movieclip and jumps to the final point in the path.  I'd like to be able to tween along a path, then send it another path and have it tween to the next final location and so on. 

 

Thanks for any direction you can give me.

 

Link to comment
Share on other sites

Hi and welcome to the GreenSock forums.

 

Its a bit tricky as a pathFollower can only be on one path at a time. Without knowing more about what you need to do, here is a basic example that has a box following a path and then following another path.

 

You can just paste this into your fla

 

import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.motionPaths.*;
import flash.geom.Point;
import flash.display.Shape;


//create a LinePath2D with 5 Points
var path:LinePath2D = new LinePath2D([new Point(0, 0), 
                                      new Point(100, 100), 
                                      new Point(350, 150)])
                                     


var path2:LinePath2D = new LinePath2D([ 
                                     
                                      new Point(10, 200),
                                      new Point(400, 200)]); 
path2.lineStyle(3, 0xFF0000);


var box:Shape = createSquare(10, 0xFF0000);


//add paths to the display list so we can see it (you can skip this if you prefer)
addChild(path);
addChild(path2);




//put a red square exactly halfway through the 2nd segment
path.addFollower(box);


//tween box along path
TweenMax.to(path, 2, {progress:1, onComplete:nextPath});




//tween box along path2
function nextPath() {
path.removeAllFollowers();
path2.addFollower(box);
TweenMax.to(path2, 1, {progress:1, onComplete:nextPath});
}






//method for creating squares
function createSquare(size:Number, color:uint=0xFF0000):Shape {
    var s:Shape = new Shape();
    s.graphics.beginFill(color, 1);
    s.graphics.drawRect(-size / 2, -size / 2, size, size);
    s.graphics.endFill();
    this.addChild(s);
    return s;
}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×