Creating a yo-yo effect in TweenLite
Although natively TweenLite doesn't support yo-yo animations, it has everything that we need to create one ourselves using callbacks. When we move into TweenMax we will see there is a built in feature that enables yo-yo animations. In this lesson, we will create our own yo-yo animation in TweenLite.
Video Transcript
00:00All right, so let's continue showcasing the different animations that we could do or the different features that are available in tween light
00:07So what I want to do is I want to create a pulsing logo literally. I just wanted to be like
00:13Literally a pulse so to do that
00:15I want to create a back-and-forth animation that will happen forever to do that
00:18What I'm gonna do next is I'm let's start with the first step of creating that initial pulse
00:23So even before that what I want to do is I want to set my logo to be a little bit smaller
00:28so to do that, I'm gonna I'm gonna approach remember when we created the tween light earlier and
00:33We set the two and we did the MC logo and we set the time to be zero and let's set whatever values
00:39We wanted to set for example. We wanted to set the scale
00:43X to 0.5 and scale Y
00:46To 0.5
00:48We want our initial value to be that remember when we did that and then it set our value without having any animation
00:54Another way to do that and probably a more intuitive way to do that is setting setting it using the set function
01:01So if I do the tween light
01:04Two instead of two
01:06I'm gonna do set and my target object is an MC logo and literally I'm doing the exact same thing
01:11I'm only not putting even the time inside so the set is kind of like a direct method of how you do it
01:17It's just wasn't available and a nano so I couldn't do that on nano. So we've set our logo
01:22we set it a little to be a little bit smaller and it's time for us to start our animation tween light to
01:28MC logo, we want it to take about let's say 0.8 seconds
01:33And we want what do we want to happen? We want to scale so I'm gonna take those scale properties that we did before
01:39I'm just gonna notch them up to one
01:42Notch them all the way up to one
01:44All right. Now that I've done that as soon as I open my application that should
01:49I'm
01:51Open all I want is to go back up and down up and down up and down
01:55So to do that the next step is I want to add here an on complete method on a complete
02:01callback and I'm gonna call
02:05And I'm just gonna create our little functions we're gonna call this on logo complete
02:11I'm gonna create that function really quickly private
02:15Function on local complete. Oh and we want to send a property. So I'm going to show you it's another
02:24Wonderful trick one wonderful cheat that you could do with tween light
02:28So I'm gonna I'm gonna on complete
02:31Params and I'm gonna send to it instead of sending it my object itself and starting a new tween
02:37I really want to have access to the tween that I've just used to do that
02:41I could send the string value of this is really really fancy really really cool
02:46I send the string value of opening closed curly bracket inside of it the word self
02:51If I do that the property that is gonna come to my element is gonna be the tween itself
02:56And if I just trace out here the tween we'll see that in the end of our animation
03:06We should be able to get in our trace line our tween light now
03:09The reason why I wanted my tween light is because I want to continue and create now a reverse of that animation to do that
03:16I'm just gonna call the tween itself and I'm gonna ask it to reverse
03:20Now by default by setting the reverse
03:23It should automatically just reverse back to the initial positions
03:28Animating in the same speed in the same duration in the same amount of time now if I wanted to I could have I could have
03:36Set different
03:37Parameters here that I'm not gonna talk about this is all at all once we go through everything
03:42I'm gonna go back because if you're gonna see this from a lot of times which enables you to jump from a specific spot in
03:48Your timeline to animate to a specific point in your time, okay, but I'm not gonna even talk about that right now
03:54I'm just gonna treat it as a reverse
03:56So it's gonna take us from wherever we were and bring us back to the beginning now one more thing that I want to
04:01Do is when my animation is complete. I would want it to actually happen again
04:07So to make it happen again, I'm gonna add here another property property
04:12Another callback and the next callback is gonna be you guessed it on reverse
04:18On a reverse complete. I'm going to call on
04:23Logo reverse complete on
04:29Reverse complete
04:31Rounds and we're gonna send to it the exact same thing. We want to have access to our
04:37We want to have access to our tween
04:40And all that's left for me to do is to create that function now that I've reversed it
04:44All it's left for me to do is now play it again because it's gonna be in the beginning again
04:48so all that's left for me to do is grab the name of the function and
04:53All I could do now is just go to the same tween and ask it to play again
04:58and
04:59If I run it again, you'll see that now it's gonna go in go out go in go out and I could play around with the
05:06Speed and maybe the size of how much it's jumping but there we go
05:09We created a pulsing logo and that's exactly what we wanted to have
