gigbig Posted February 14, 2013 Posted February 14, 2013 Hi, I am trying to tween a number that grows progressively: I have a totalAmount and the number of total steps to reach it. I should have something like this: TweenLite.to(this, totalTime, { ***textfieldText: totalAmount***, ease:SteppedEase.create(steps) } ); My problem is: how can I increase the amount in a textfield at each step? I tried a few solutions, but I don't know how to execute actions at each step. I have the onUpdate property, but it is synchronized with the tween updates, not the step event. Maybe I am missing the onStep property or something similar...
Carl Posted February 14, 2013 Posted February 14, 2013 Yes, stepped ease does not have any events. The basic idea is you tween a numeric variable and then use an onUpdate to apply that number to a textfield. Take a look at the tutorial and source code and files here: http://www.snorkl.tv/2010/09/how-to-tween-a-variable-with-flash-and-tweenlite/ If you plug in your stepped ease do you get the effect you want?
gigbig Posted February 17, 2013 Author Posted February 17, 2013 Well, yes, it works, but that way I am updating both the score (rounding it to int) and movieclip once per ENTER_FRAME, and not 10 times as it seems. I could add a variation check (if score != previousScore) to avoid redrawing the gfx when not needed. If I could intercept the STEP event of SteppedEase I could write very short, efficient and clean pieces of code. It could be a cool addition for future GSAP releases
jamiejefferson Posted February 18, 2013 Posted February 18, 2013 Hmm something super simple like this should be more than fast enough for the tween you are after: var score:int = 0; var currentscore:int = score; var targetScore:int = 20; TweenLite.to(this, 1, {score:targetScore, onUpdate:showScore, ease:Linear.easeNone}); function showScore() { if (score !== currentscore) { score_mc.score_txt.text = currentscore = score; } } It's one function call and one strict comparison per update, and only changes the textfield when the number changes. I can't imagine any of this being a performance issue.
gigbig Posted February 18, 2013 Author Posted February 18, 2013 Yes, you're right, this case is very simple and I am not working on an 8088 anymore, but for very complex contexts an event phylosophy would be more clear and efficient, don't you think? I don't know if a new property "onStep" is in the plans of the future releases (it would be specific just for this ease), but it sounds very natural to me, when using a "step" parameter.
GreenSock Posted February 18, 2013 Posted February 18, 2013 Actually, callbacks are much faster (better performance) than events. And the challenge with implementing a special callback/event for only SteppedEase is that it could create some confusion with the other eases, like "wait, why does SteppedEase do it and other eases don't?" And the bigger issue has to do with the fact that this sort of feature would have to be baked into the core engine which would add conditional logic to the most critical, performance-intensive function in the entire engine (thus slowing things slightly for everybody). So I think it's much better to implement something external like Jamie's solution instead. See what I mean?
gigbig Posted February 19, 2013 Author Posted February 19, 2013 Well, you are the guru Jamie's solution is good, I am adopting equivalent solutions for various cases. I was just wondering if an event system could be possible, but it looks like it would be the wrong way to proceed. Ok! No, problem! Thank you Jack and Jamie!
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