Scrubbing animations
Every animation in TweenLite has a timeline. In other words, you can scrub it and move in any point in time just like you would with a video player. In this lesson, we will introduce this concept and see it in action as we jump in using the seek command.
Video Transcript
00:00To showcase the next batch of properties methods that we want to look into, I've copied from
00:06Chapter 2 that text animation that we've created earlier, let's just look at it really quickly.
00:12I didn't make any changes to it, I just changed here the copy, we have our tween that we
00:16created in Chapter 2, and we have all the information that we provided earlier on.
00:21Let me just reposition our tween, so before you even do anything, I'm going to go tween
00:26light, and I'm going to set its position of our target, which is T names, and I'm going
00:32to set, let's set the X position to be, let's say, 50, and we're going to set the Y position
00:41to be really low on the screen, so let's do that stage, stage height, minus 200, and I'm
00:48going to set the width though, so to be much bigger, so I'm going to set the width, so
00:52let's say 500, so let me just see if this looks fair, okay great, so this is more or less in
00:58a good position, probably, oh, because we're centered, we probably would want to center
01:02the X position, so let me just stage, stage width divided by 2, that should work, so we'll
01:10be right under, what am I doing, that doesn't look good at all, oh, and we want to subtract
01:18Oto, the T name, start width divided by 2, right, that should, I know, we want to subtract
01:28the whole T name, right, yeah, you know, it takes me five times, but then I figure it
01:33out, there we go, okay, so that's exactly where we want our animation to be, sign for
01:37us to start really defining it and changing our animation, to make this happen, what
01:43I'm going to do in the next stage is I'm going to go right after I create my tween,
01:48that is, if you recall, calls are on update text and updates are text, I'm going to go
01:53ahead and just tell that text tween to pause, literally forcing it to stop, so now that
02:00animation is not happening anymore, our text isn't really doing anything.
02:04Now that I got that sorted out, I want to add another event and this time I'm going
02:07to approach my stage and I want to create a mouse event, so I'm going to add an event
02:12listener and I'm going to call a mouse event and I'm going to call a mouse move,
02:16mouse move event, which basically every time our mouse will move on move, it will
02:22be called and I'm going to call that function, create that function, private
02:26function on move, it's going to be a mouse event and really what I want to do
02:33is I want to create a value between 0 and 1, so let me check what value could
02:39give me that and that would probably be my stage x position and I want to take my
02:44x stage position and divide it by my stage.stage with, that will give me a
02:50value between 0 and 1, so as I am going around from one position to the other
02:55position, my value should be growing all the way to 1, going all the way to 0
03:00and I'm noticing if I go out of the stage I might create a little bit of a
03:04mess up, so I might want to round it down but I am going to let it be for now, so
03:10this value that I got is exactly what I want. Now what I want next is I want to
03:15take this value and I want to duplicate it by the actual duration of our
03:20animation, that's currently 10 seconds, but I'm going to go to my tween, my text
03:24tween and I'm going to ask for the duration and I'm just going to take that
03:29duration from it and duplicate it by that value, that way my duration, the
03:33value of the duration, I'm going to get your value between 0 all the way up to 10
03:38or 10 ish. Alright perfect, now that I got that value, all that's left for me to
03:44do is to take this value and set my tween, my text tween, I need to set my time
03:54and by setting the time I'm basically forcing a re-render of the screen
03:59basically setting it and resetting my current position, so let's see how
04:04what will happen once we do that. So as you see as I move my mouse now the text
04:08is going to start writing itself or deleting itself based on my mouse
04:11position. Now you could probably imagine a few cool really effects such as when
04:15you're rolling onto a button and as you get closer it gives you the information
04:19and as you roll out of it the information types itself away based on
04:23how far you are from that button and so on and so forth, there's some really
04:27cool effects that you could do just with this little small little tip. Now I wanted
04:32to talk about another thing because there's a method called time and there's
04:35another method called seek. Now the only difference between seek and time is that
04:40seek by default suppresses the events and thus if I would call the seek
04:45instead of the time what would happen is nothing because we need the events
04:50to happen because the events are actually calling the on text update
04:53which is what's updating our text. The animation is not doing anything because
04:57animation is actually happening inside of our event which is on update. So if
05:01we're suppressing the events which is the default for seek, then we
05:06wouldn't see anything but we could override that default and set it to false
05:09and if we set it to false then our seek command should work just as well
05:14as our time did. So literally the only difference between seek and time is
05:19that seek by default it prevents the events from triggering
05:24while time by default it does. It doesn't suppress the events and lets the
05:29events happen. So literally the only difference between seek and time is
05:32that are you actually suppressing the events or not?
05:41And by the way one more thing that is different is that seek
05:45itself we are actually we're actually changing something versus time we could
05:49even just call it to get the actual time that we're in and we don't have to
05:53actually set something. So it's also a getter and also a setter while seek is
05:57actually a command that is more of a more targeted so I'm guessing that the
06:00need time there's a seek that actually the time calls some sort of a seek
06:04behind the hood of probably
