Jump to content
Search Community

Not the right time

Sourivore test
Moderator Tag

Recommended Posts

Hello, everybody.

 

I have a problem with my tweens.

 

I have those tweens :

 

function f() {

TweenLite.to(mc, 0.25, {rotation:50, delay:0, overwrite:false});

TweenLite.to(mc, 0.5, {rotation:-50, delay:0.25, overwrite:false});

TweenLite.to(mc, 0.25, {rotation:70, delay:0.75, overwrite:false, onComplete:f});

}

 

The problem is that there is not exactly 1 second between each loop as it could be.

 

That means that there is a gap between all my animations. That is very problematic, especially when you try to animate a character walking (with legs and arms animated) and you want all the animations are synchronized !

 

Thank you if you have the same problem or a solution.

  • Like 1
Link to comment
Share on other sites

Perhaps there are other factors affecting your performance, but I think you will find that the timing of TweenLite is incredibly precise.

 

replace your code with the following:

 

import com.greensock.*;
import com.greensock.easing.*;
var lastTime:Number = getTimer();
var now:Number;
function f() {
now = getTimer();
trace(now - lastTime);
lastTime = now;

TweenLite.to(mc, 0.25, {rotation:50, delay:0, overwrite:false});
TweenLite.to(mc, 0.5, {rotation:-50, delay:0.25, overwrite:false});
TweenLite.to(mc, 0.25, {rotation:70, delay:0.75, overwrite:false, onComplete:f});
}
f();

 

that will trace out how many milliseconds transpire between the first tween being created and the last tween completing.

 

you will see that only 1000 milliseconds transpire. occasionally there may be a variance of a few thousandths of a second. considering that Flash can only process data and render a set number of times per second (based on framerate), this variance is expected and unavoidable.

 

are you getting drastically different results?

Link to comment
Share on other sites

First I'll describe the problem, then the solution...

 

The problem has to do with the fact that all tweening engines are updated on some sort of interval, and the best one is tied to the frame rate (that's what the GreenSock classes use - an ENTER_FRAME event). The interval cannot be relied upon to always be precise because, for example, the user's computer could bog down with some other process or Flash might have to calculate a bunch of update to the screen and temporarily drop some frames, etc. So let's say your frame rate is 30fps and you have a 1-second sequence of tweens that then calls a function to repeat itself (as your script did). If the frame rate lags at the end slightly, like by 100ms, that means that the very last render (which calls the onComplete) would be off by about 100ms. There's absolutely no way to avoid that - if the processor is bogged down doing other things, you simply cannot tell it "oh, forget all that other stuff and make sure you call the tweening engine's update routines with perfect frequency". So now your next loop of the tween starts 100ms late. And if the same thing happens on your next cycle, you'll be a total of 200ms off, and so on...

 

Now the solution...

 

This is precisely why I put a bunch of effort into building logic into the TimelineMax and TweenMax classes that handles repeats as elegantly as possible without allowing gaps like described above. Many other engines go the simple route of "when the tween/sequence is done, make it start again" but that's what leads to those gaps described above. TimelineMax and TweenMax, however, calculate things from the very beginning of the timeline/tween and don't allow the gaps. So you can simply put your tweens into a TimelineMax and set its repeat to -1 to repeat infinitely and you shouldn't get any gaps. That way, in the example above even if there's a 100ms delay with the CPU getting bogged down at the end of the first cycle, instead of starting the next cycle 100ms late, it will simply render the next cycle as 100ms into its progress already.

 

Make sense?

  • Like 2
Link to comment
Share on other sites

I thought about TimeLineMax. You confirmed that and your answer is precise and I thank you for that.

 

I'll try this as soon as possible because variations for animations as complex as a person walking, is unacceptable and the result is very...odd.

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