Jump to content
Search Community

How can I get the init / current tween vars?

TyZ test
Moderator Tag

Recommended Posts

I have this object that can have multiple tweens over time. But I want to go back to his original state at any time. I also want to store the current tweenvars of the object at anytime, so I can tween back to that state.

 

So I need somthing like:

var tween:TweenMax = TweenMax.to(object, 1, {...});
this._startVars = tween.startVars;

 

after some time do some more tweens. (Could happen more than once)

 

var tween:TweenMax = TweenMax.to(object, 1, {...});
var currentStartVars = tween.startVars;

// and now append the currentStartVars to my _startVars (maybe I am tweening different properties in my seconds tween, so we need those in my _startVars as wel) Maybe the OverwriteManager can do something like that?
OverwriteManager.appendVars(this._startVars, currentStartVars);

 

And than I want to go back to my orginal state:

TweenMax.to(object, 1, this._startVars);

 

The other thing I want is to get the current tweenvars at any time (also when tweens are running)

this._currentVars =  TweenMax.getCurrentVars(object);

 

So at anytime I can go back to that state I just saved in the _currentVars:

TweenMax.to(object, 1, this._currentVars);

 

Is something like this possible?

Link to comment
Share on other sites

Sure, you can do pretty much all of that, but it's not something that should be in the core functionality of the tweening engine - you should do that stuff externally. It sounds like 2 functions would do pretty much all of what you wanted:

 

//clones an generic object like the one typically passed into TweenLite/Max:
function cloneObject(obj:Object):Object {
   var newObj:Object = {};
   for (var p:String in obj) {
       newObj[p] = obj[p];
   }
   return newObj;
}

//combines obj1 and obj2 (obj2 overwrites overlapping properties in obj1)
function combine(obj1:Object, obj2:Object):Object {
   var newObj:Object = {};
   var p:String;
   for (p in obj1) {
       newObj[p] = obj1[p];
   }
   for (p in obj2) {
       newObj[p] = obj2[p];
   }
   return newObj;
}

//creates a new vars object based on the current values in a tween (this does NOT work for plugin data like filters)
function captureBasicState(tween:TweenLite):Object {
   var ignore:Object = {ease:1, delay:1, overwrite:1, onComplete:1, onCompleteParams:1, useFrames:1, runBackwards:1, startAt:1, onUpdate:1, onUpdateParams:1, roundProps:1, onStart:1, onStartParams:1, onReverseComplete:1, onReverseCompleteParams:1, onRepeat:1, onRepeatParams:1, proxiedEase:1, easeParams:1, yoyo:1, onCompleteListener:1, onUpdateListener:1, onStartListener:1, onReverseCompleteListener:1, onRepeatListener:1, orientToBezier:1, timeScale:1, immediateRender:1, repeat:1, repeatDelay:1, timeline:1, data:1, paused:1};
   var newObj:Object = {};
   for (var p:String in tween.vars) {
       if (!(p in ignore)) {
           newObj[p] = tween.target[p];
       }
   }
   return newObj;
}

 

If you need to get the current state including plugin data, you'll need to write a more complicated function to parse that data specifically.

 

Also, remember that in v11, you can pause() any tween and get/set its currentTime value. Render it at any point like myTween.currentTime = ANY_TIME. You can also reverse() anytime or create sequences with TimelineLite/Max. But if you're going in a lot of different directions with different properties and want to tween between disconnected spots in a sequence, you will probably need to use the methods above (or something similar) to track the various properties.

 

Have fun :)

Link to comment
Share on other sites

You must find that data yourself, so if there's a BlurFilter applied, you'd need to find it in the object's filters array and record the current blurX/blurY values, etc. There is no simple/easy solution.

 

The reason I don't add that kind of functionality to the tweening engine is because:

 

1) It would require adding new code to every plugin which increases the file size and complexity.

 

2) It is an extremely uncommon requirement. If I add the code, though, it increases the file size for EVERYONE and potentially degrades performance a bit.

 

I hope you understand why I'm so protective of both the file size and performance of the engine - many engines have suffered from "feature bloat" that caused them to get really fat and slow - I want to avoid that. I'll keep this scenario in mind, though, for future development - maybe I can figure out an elegant way to accommodate this sort of thing at some point.

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