Jump to content
Search Community

dynamic change direction of LinePath2D

maximaexchen test
Moderator Tag

Recommended Posts

Hi Jack, hi all.

 

I try tu figure out how to change the direction and speed of a looped LinePath2D Animation on mouseClick.

 

If I understand it right, CirclePath2D has a direction property, but I can't find out to change it eventdriven.

 

Program Snippet:

 

myTween = new TweenMax(path,_timeScale, {repeat:-1, ease:Linear.easeNone, progress:1});
...
mouseEvent -> calls changeSpeedDirection from other class
....
public function changeSpeedDirection(duration:Number, newDirection:String):void
{
if(newDirection == "right") {
               //change direction Direction.CLOCKWISE
       } else {
	//change direction Direction.COUNTER_CLOCKWISE
}

myTween.restart(false, true);
myTween.duration = duration;
myTween.repeat = -1;
}

 

The speed changes perfectly, but the dirction?

 

Maybe someone could help?

 

best regards

Link to comment
Share on other sites

Well technically the reverse() is behaving correctly because it's going back to where you started. If you called reverse() after it had repeated twice, it would go backwards for 2 cycles. See what I mean? In any case, I'd just use a relative value and recreate my tween like this:

 

public function changeSpeedDirection(duration:Number, newDirection:String):void {
  if(newDirection == "right") {
       myTween = new TweenMax(path, duration, {repeat:-1, ease:Linear.easeNone, progress:"1"});
  } else {
       myTween = new TweenMax(path, duration, {repeat:-1, ease:Linear.easeNone, progress:"-1"});
  }
}

Link to comment
Share on other sites

Thanks Jack!

 

That was the way I tried it before ...

but if i do it like so, the speed is not handled correctly.

Everytime the function is triggered the Tween becomes slower and slower.

 

If I just call: myTween.duration = duration; without recreating

everything is fine, except the direction thing....

Is it right that I change the speed over the duration parameter?

 

Do I have to "kill" or overwrite something?

 

Thanks in advance

Link to comment
Share on other sites

No, you don't have to kill anything - TweenMax will automatically overwrite the previous tween of the same property. You can set overwrite:true if you want which would make things ever so slightly faster when the tween initializes but really, it's nothing you'd notice.

 

I just tested this theory and it worked perfectly for me - no weird slowdowns or anything. Can you please post an example that demonstrates the problem? Like I said, it worked like a charm for me so I'm kinda baffled. I wonder if there's something else going on in your code.

Link to comment
Share on other sites

Ok.

 

So attached an example.

If you click the buttons left - right - left - right an so on.

the path has different speeds....to left and right, but they should always have the same speed.

 

And in my project the speed reaches 0 (most in very short paths) after some switches....

I think I use the duration parameter the wrong way.

Link to comment
Share on other sites

Nope, the problem is that you didn't do relative tweens like I said to above :) Notice my progress values had quotes around them? That makes them relative. You were using absolute values. Cast your progress values as Strings and you should be good to go.

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