Jump to content
Search Community

LinePath2d - sprite use

trixiemay test
Moderator Tag

Recommended Posts

You can add pretty much any object as a PathFollower on your LinePath2D and you can tween any object's rotation with a simple tween, like TweenLite.to(myObject, 2, {rotation:270}). Have you checked out the docs on LinePath2D?

http://greensock.com/as/docs/tween/com/greensock/motionPaths/LinePath2D.html

 

You'd need the addFollower() method.

 

Does that help?

Link to comment
Share on other sites

Here's some sample code - you'd just replace "yourObject1", "yourObject2", and "yourObject3" with your objects (and of course add as many as you want).

 

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

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

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

//create an array containing your objects
var targets:Array = [yourObject1, yourObject2, yourObject3];

for (var i:int = 0; i < targets.length; i++) {

   //we'll place each one at a random spot on the path
   var progress:Number = Math.random();

   //create a PathFollower, placing the target on the path at the random spot
   var follower:PathFollower = path.addFollower(targets[i], progress, false);

   //now tween the follower's progress from its current position plus one whole cycle, thus making it loop. We repeat infinitely too.
   TweenMax.to(follower, 10, {progress:progress + 1, repeat:-1});
}

 

If this doesn't make much sense, you might want to consider hiring a professional developer to help you write the code and get exactly the effect you're after.

 

Happy tweening!

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.
×
×
  • Create New...