02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Creating a yo-yo effect in TweenMax

Creating a yo-yo effect in TweenMax is incredibly intuitive and easy because it is built into the core features of this animation Library. In this class, we will see how to create a yo-yo effect in TweenMax.

Video Transcript

00:00All right, let's get chapter five rolling. So to do that, I'm going to go ahead and just start from
00:05a basic tween. I'm going to go ahead, but this time around use my tween max. So I'm just going
00:10to make sure that it's imported, which it is already. So I'm going to go ahead and create
00:15a new tween. And this time around, I'm just going to take my element, I'm going to take my
00:22shape that we've just had here, I'm going to give it a duration of one second again.
00:26And let's just change the scale x. Let's change it to be three. We're going to scale y. We're going
00:32to do that as three as well. Let me just run it. Same old, same old, we've seen this done before.
00:38Now, what if we wanted this animation to repeat itself a certain amount of times? So to make this
00:45happen, all I have to do is add another property, which is called re eat. And I could set how many
00:52repeats I want. For example, if I wanted to repeat three times and I run it again, we'll
00:56see that it's going to go one, two, three. Now, by the way, because it includes zero,
01:02so this is time zero times one times two times three. Okay, so the three here actually is four
01:09times of repeat three. And if I wanted to happen indefinitely, all I have to do is set
01:14your repeat minus one. And if I set the value repeat minus one, then it's going to go
01:19indefinitely, never stopping. Now, let's see one more thing. What if I wanted to create a delay
01:25between repeats? How about if I wanted to create, let's say, let's say, repeat, well, let's just
01:34figure out how much delay, let's say a half a second of a delay, repeat, delay, uppercase for
01:40the D, and we're going to set here, let's say a quarter of a second or 250 milliseconds for our
01:46delay. So now if I run it again, we'll see it's going to get to its position, wait a quarter of a
01:50second, get to position, and so on and so forth. Now, one more thing, what if I wanted my animation
01:57to go back and forth like a yo-yo? Well, surprisingly, you call it yo-yo, because that's
02:02exactly the name of the property. All I have to do is set the property of yo-yo and define it to
02:08be on repeat mode as true. And if I do that, we'll see our animation is going to go in,
02:14going to go out, going to go in, going to go out. And there you go. That is our first, first, first,
02:22first new properties with tween max. I want to talk about just one more before we wrap up this video
02:28by telling you that we could also add your property called paused. Now the property pause,
02:33if I set it to be true, is going to initially start my application with it paused. So before
02:39I even stop, how about I'll add a quick click event. So I'm going to go ahead, I'm going to add
02:44an on click event to our shape. So I'm going to add here to my shape, which is not a clickable
02:52event because it's not an interactive element our shape right now. So I actually can't make that
02:56clickable. But how about I'll add to my actual stage itself right now, or change it from being
03:02a shape, our circle creator, to something that is a little bit more dynamic, such as a sprite,
03:07which has user interactivity. So to do that, I'm going to just change here a little bit of
03:12stuff. So instead of creating shapes here, I'm going to create here a sprite. You know what,
03:18let's keep this for the next video, because it's going to be a little bit long. So in the next
03:20video, we're going to turn our objects into be something interactive. Now that we've paused it,
03:26and we're going to create anytime we click on it, we'll start playing it. And anytime we click on
03:30it again, we'll pause it again. So we'll see you in the next video when we do that.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!