Jump to content
Search Community

AS2: Oscillation with changing amplitude [SOLVED]

tfranz test
Moderator Tag

Recommended Posts

Hi,

 

i want to script an everlasting oscillating movement with changing amplitudes – but i can't get it to work ... :-(

 

import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;
TweenPlugin.activate([DynamicPropsPlugin]);

function getAmplitude():String {return String(50);}

TweenMax.to(my_mc,1,{dynamicProps:{_y:getAmplitude}, repeat:-1, ease:Sine.easeInOut, yoyo:true});
//TweenMax.to(my_mc,1,{_y:"50", repeat:-1, ease:Sine.easeInOut, yoyo:true});

 

If i use the last line of code, the tweening is okay. But i want to change the _y:"50" to different values, so i tried it with dynamicProps – but the effect is completely different as i expected ... if i use the code with the dynamicProps i expected the same behaviour ...

 

Second question: is there an "ease:" with a +/- movement? ease:Sine.easeInOut is from (example above) 0 to 50 to 0, but i would like to have 0 to 25 to 0 to -25 to 0 ...

 

Thanks for your help,

 

Tobias

Link to comment
Share on other sites

When a tween inits, it normally figures out the start and end values. Then when you repeat, it goes back to the start value again, etc. If you yoyo, it goes from the end back towards the start value, etc. However, when you use dynamicProps, it's completely different because there is no longer a normal start/end - everything is dynamic. It's constantly adjusting values on the fly, trying to plot its way to that new destination value over the duration of the tween. And dynamicProp functions are supposed to return Numbers, not Strings. So in your case, the tween used the dynamic value of 50 and constantly plotted its way there. Then when the tween finished (and had arrived at 50), it repeated and again, but there are no hard-coded start values to go back to - it was all constantly changing. Recording the points internally as the tween progressed isn't very feasible because it would get memory intensive and there are a few other complexities that would complicate things. The moral of the story: don't repeat dynamicProps tweens.

 

As for your 2nd question, an easing equation will ALWAYS go from the starting value to the end value, so if your tween defines that you want _y to end at 50, no easing equation should make it go to -25 and then have it land at 25 - that would be incredibly frustrating for users to not have it honor the end value they set. However, you can definitely have an easing equation that dips to negative values before coming back to the end value. You could accomplish that by either writing your own easing equation or using CustomEase (http://blog.greensock.com/customease/). You could also just do a bezier tween to make your object travel down and then up again smoothly. See the bezier and bezierThrough plugins in the Plugin Explorer.

 

Hope that helps!

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