flashdev Posted November 10, 2013 Share Posted November 10, 2013 Hello, I'm trying to use a single tween, to tween a object sometimes.. I don't want create a TweenMax object every time, like TweenMax.to(...);Whats the better way to do this? Is possible?Something like this: private var tween:TweenMax = new TweenMax(object, .6, {}); // Just a example, this will be active when the user click in a button tween.to({x:20}); Thanks Link to comment Share on other sites More sharing options...
Carl Posted November 11, 2013 Share Posted November 11, 2013 Here is a demo of how how to do it var t = TweenLite.to(mc, 1, {x:0, onComplete:reUseTween}); function reUseTween() { t.invalidate() t.vars.x = 500; t.restart() } Admittedly, I don't know why or how this is needed in your project, but I'd be reluctant to suggest that this is better than just creating a new tween. Link to comment Share on other sites More sharing options...
flashdev Posted November 11, 2013 Author Share Posted November 11, 2013 Do you think there would not be a minimal performance gain?I'm adjusting my code to save the largest resource possible, this is why.I'm practicing to future build for mobile with Starling.Thanks! Link to comment Share on other sites More sharing options...
GreenSock Posted November 11, 2013 Share Posted November 11, 2013 First of all, I applaud your efforts to improve performance even if it means writing more code. I'm a big performance freak, so I appreciate your goals here. To answer your question, no, I don't think it's generally wise to put so much effort into reusing the same object. I've done some testing of my own and while it's wonderful to avoid garbage collection, there are costs involved with object reuse that people often ignore. Some people get so hyper-focused on object pooling and avoiding GC (in an effort to improve performance of course) that they don't consider the cost of cleaning those objects and they often end up getting worse performance. When I tried implementing some object pooling logic in the core, the engine actually performed slightly worse. Blog articles often make it sound like reusing objects is an obvious thing that everybody should do, but they're often working with theoretical or highly synthesized test cases, but then when you try doing it in real-world projects it's can be a very different thing. Feel free to do your own tests, but my guess is that you'll see either no performance benefit or you'll actually get slightly worse performance with the object reuse (at least in this case with tweens). Link to comment Share on other sites More sharing options...
flashdev Posted November 12, 2013 Author Share Posted November 12, 2013 First of all, I applaud your efforts to improve performance even if it means writing more code. I'm a big performance freak, so I appreciate your goals here. rofl, this was funny! Well Jack, I really don't need tests, I know your work and dedication on this platform for a long time now, your experience speaks for yourself. Thanks for your time reporting your experience. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now