Jump to content
Search Community

MotionPath.addFollower - PathFollower progress prop problem

szaqal test
Moderator Tag

Recommended Posts

Just for efficiency. I'm a bit of a performance freak - you shouldn't use cachedProgress, though - that's generally meant for internal use and it wasn't possible to use private/protected variables because other GreenSock classes needed access to them. That's why I named them "cached___" :)

 

Why do you ask?

Link to comment
Share on other sites

Because I've extended the PathFollower class to monitor the progress property in the progress setter. I'm building a carousel and I want to manage elements by PathFollower progress property like:

 

override public function set progress(value:Number):void
{
super.progress = value;

if(super.progress < 0.75)
{
  super.target.alpha = 0;
}
}

 

My current concept is that each of the pathFollowers should monitor its progress and perform actions on their targets.

 

Jack if you have any suggestions how to achieve that please give me a tip :).

Link to comment
Share on other sites

Sure, you can use this updated MotionPath class (attached). I'll put it into the next release that I push up to the main site too. Also, I'd recommend setting visible = false instead of alpha = 0 unless you need mouse interactivity on the invisible elements. visible = false will perform much better than alpha = 0.

Link to comment
Share on other sites

Jack shouldn't the f.cachedProgress in progress setter (in MotionPath class) be also changed to f.progress? The new class works fine when I add followers but when tweening nothing happenes. The distribute function also modifies f.cachedProgress.

Link to comment
Share on other sites

No, I don't want to make that change because it's too costly in terms of performance. One of my goals in building the MotionPath stuff was to optimize performance so that you could have literally hundreds of PathFollowers going at once. If I do what you're suggesting and I have 200 PathFollowers on the MotionPath, for example, every time the MotionPath's "progress" gets updated, it would add 200 function calls (and keep in mind that while tweening, this may happen 30 or 60 times per second which could add up to literally 12,000 function calls per second). Functions are one of the more expensive things to execute in ActionScript (MUCH more expensive than setting a public property). See the problem?

 

So in your case, it would actually perform better if you manually did that checking/updating yourself, kinda like this:

 

TweenLite.to(myMotionPath, 2, {progress:1, onUpdate:updateFollowers});
function updateFollowers():void {
   var i:int = followers.length;
   while (--i > -1) {
       followers[i].target.visible = Boolean(followers[i].progress >= 0.75);
   }
}

 

Make sense?

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...