Jump to content
Search Community

Switching tweens in mid-progress and accuracy

Luken test
Moderator Tag

Recommended Posts

Hello! I have a question :) . I'm making a class what job is to apply more complex tweening effects on vector of BitmapAssets (like bouncing snake etc). I want to be able to switch to second effect in mid of the first effect etc, so I achieved this by using timelines and optional arguments (I have one main timeline, and smaller timelines of specific effects and tweens). Now, the problem is that if I'm interrupting few tweens, switching them to others, accuracy is lower and lower (when i'm tweening relative values), and even if theoretically after last effect, the snake of bitmaps should land od the same y position - it doesn't. Can it be avoided? Maybe I'm not using these classes properly. I'm starting new effect by calling:

 

private function nextTimeline(timeline_:TimelineMax) : void {
  if(timeline_.nextNode && !timeline_.nextNode.initted) timeline_.nextNode.restart();
}

 

If it's not possible to secure accuracy I will try to correct things on the fly, but it won't be easy and will hit performance as it would propably involve some onUpdate listeners, logging theoretical final positions, and a lot of new tweens.

 

Regards!

Link to comment
Share on other sites

You definitely should NOT be tapping into the _nextNode stuff. I don't understand why you're doing that in the first place, but that property is undocumented and only intended for internal use (it had to be exposed as a public property for performance reasons).

 

I don't really understand what you're trying to accomplish. Does "switching tweens" mean you want to update the destination values on-the-fly? Maybe if you described a very simple example in detail, it would help. I'm pretty sure there's a much better way to approach what you're doing, but I've got to understand what the goal is specifically in order to make sure I'm giving you solid advice.

Link to comment
Share on other sites

Ok, so I will describe better :) . I have one class - CVectorAnimator, and few classes with animation effects, which essentially just tweens in various way a vector of bitmaps (getting them by reference through constructor), and have method "start()" that gets arguments, creates a timeline with proper tweens and returns that timeline - after that the CVectorAnimator adds that timeline to its mainTimeline. Essentially I can just call from the main class a set of effects and they start one after each other. Pretty basic. But the problem begins when I try to have a possibility to start one effect in mid-air of other effect (with using actual bitmaps positions), and it involves a tween collision. I found (by tries and errors) that timeline_.nextNode.restart(); allow me to accomplish that - it basically stops one timeline with all tweens and starts next (by experience). I didn't know that it's only for internal use :) . However when I'm doing it, results are not accurate.

 

It will be the best if I will show that: http://kolibrary.webd.pl/flash/snake/ in the result, the squares should be at the same distances to each other, and in line. They aren't. But they will be if I will start that effect as first.

 

I hope now everything is clear :) .

Link to comment
Share on other sites

I'm sure the problem is with my sleep deprivation and inability to wrap my brain around this right now, but this is about as clear as mud to me. I don't want to know about the structure of your code, constructors, vectors, blah, blah - I just want you to describe the simplest motion that you're trying to achieve and where things are breaking down. For example:

 

"Let's say I want to move box1 from x:0 to x:100 and then at some arbitrary point inbetween, I want to change box1 to go from wherever it is to x:200" (that's just an example)

 

Again, all I need to know is the end goal, not the mechanics of how you have things set up now.

Link to comment
Share on other sites

Ok, I'm sorry if I didn't explain this clear enough. The goal is to be able to have multiple timelines, of motions of the same objects, and to be able to switch between them, play one after another, and also stop one in the middle of motion, and then start another - and all that with accurate outcome :) (so if theoretically the items would end up in line, in process of many different motions, it would happen practically). Is this possible?

 

Once more sorry for bad explaining, and thanks for trying to help ^^ .

Link to comment
Share on other sites

Yeah, that still didn't help :) You keep explaining the theory and mechanics (various timelines controlling the same object) but I want to know specifics about the motion. The simplest possible way to describe it.

 

You can definitely have multiple timelines and control them independently. That's no problem whatsoever. I'm having a hard time understanding the "inaccurate" behavior you're getting because I can't imagine a scenario in which a tween would have inaccurate results. I can honestly say I can't remember ever hearing of that - they're specifically engineered to lock in the values and never vary from them. It's not like the tween would somehow have its end values drift over time.

 

Maybe what would be best is if you created the simplest possible FLA (tween only one or two objects) that clearly demonstrates the odd behavior you are getting so that we can publish it on our end and see what's going on. Again, the simpler the better. Do not post your production files. And don't forget to zip your file before posting here.

Link to comment
Share on other sites

Maybe try this code, I was thinking about this problem and managed to optimize my method greatly but the problem with inaccuracy still exists - try this code http://pastebin.com/L9KuDQkp :) . Often it works ok, but sometimes it ends up really bad, and it's definitely also lag-related, because if you will move your window rapidly, the outcome will be disastrous. So it looks too risky for practical use. Also note that if you will use ONLY last motion, the outcome will be perfect in any case, even if you will create a lag. So the problem lies in switching between motions.

 

Regards :) .

Link to comment
Share on other sites

I think I see the problem - you're creating overlapping tweens of the same properties of the same objects which causes overwriting to occur. Notice you did an append() with a negative offset (meaning there will be an overlap) - so you have TWO timelines that are BOTH trying to control the "x" (and maybe even "y" depending on how much of an offset) property of your object(s). Obviously one must win - x cannot be 2 values at the same time. So overwriting occurs as soon as the new tweens start.

 

Since you're doing a RELATIVE tween for "y", that would explain why you think things are getting inaccurate, but I'm pretty sure TweenMax is doing exactly the correct thing. For example, let's say y starts at 0 and you're doing a relative tween of "100" but halfway through the linear tween (when the value is 50), another relative tween starts that's "200". So that means it will end up at 250 (the current value 50, plus 200 = 250) but maybe you were expecting it to end up at 300 (first relative tween was 100, second was 200, add them together to get 300). See the issue? It's a logic flaw in your code, not in TweenMax.

 

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