Completing the manual mode
In last lesson we started creating a manual setting but didn't finish it. In this lesson, we setup the manual mode logic, enabling manual or automatic recording mode.
Video Transcript
00:00You know like with a lot of other things a moment of break of really clears the mind
00:05So as soon as I press the pause button and I'm like the pressure was over because you guys weren't watching me
00:10I was like, oh, okay. That's what I was doing wrong
00:12So let's go right back into it and continue figuring it out and getting that full component ready. I did not start recording
00:19I didn't even do I didn't start editing at all
00:21We're in the exact same spot that we were left in last lesson because I think it's really important to see that process
00:26I just didn't want you to watch me think and that's exactly what I was doing for the last few minutes
00:30So now that I'm done thinking let's go back into it and get it done
00:34It just came to me and my problem is is that I'm
00:38Setting my opacity in that specific point in time
00:42And what I really want to do is I want to set my opacity to zero from the beginning
00:47Because if you go back before I set my opacity to zero, it was never set to zero
00:52So if I go ahead here and I'm gonna go here my to my TL. I want to set that opacity completely separately
01:00CET and
01:02I'm gonna just go ahead here for my SVG and I'm gonna set my opacity
01:07Just the just the same way only instead of doing it together
01:13Although oh, yeah, I could actually do this whole thing together. I could set this initially that's fine
01:18But what I want to do is I want to add that property and just set the actual position to be zero
01:22So I'm forcing it to be in the beginning beginning of our playhead
01:26No matter at what stage we're adding the element and goes into it to my mom if you've heard that
01:32Gesundheit, so I'm gonna click on refresh. I'll add an item
01:36I'm gonna add another item and move it. I'm just gonna replay and see that one item at a time is appearing
01:41Bingo beautiful. So now we should have a
01:45logic that is
01:47Perfect. And now we're ready to start working on that auto manual part that we had there
01:52So if I just replay this just to see if that really is
01:55animating the way we want it to
01:58Not really I think it's I think that has to do with the speed that we did us
02:03But let's just refresh this do one more test and see if it's really working. Okay, so one
02:09I'm gonna add it here. Add it here. Add it here. Add it here
02:14I'm gonna add another item have it move around
02:19slowly slowly until they meet and
02:25Let's do a replay. So what is our initial animation is working really? Well, every animation afterwards
02:35Seems like it's jumping. All right, but we're definitely getting warmer. So let's revisit that spot where it's jumping and
02:42Understand why is it jumping?
02:44So that first animation is taking place and maybe one of our problems is that our amount of time that we're giving it is really low
02:51So let me check if that's really what's going on and to do that
02:54I'm just gonna do a console log just to know how many seconds we're actually giving it
03:00I'm gonna save it and just look at it just for a second here just to get a good
03:07kind of like
03:09Feel if everything here seems logical
03:11so I'm adding here a 2 to wherever the item actually is already and
03:19That is probably my problem because I'm doing a 2 and my item actually is already in that position
03:25Literally, that is my problem. I actually have to use the from 2 because when I'm doing this to
03:32The item is already in that spot. So when I'm taking my animation from place to place
03:36It's actually doing it's actually taking it to that spot. So I have to I have to use this time this timeline
03:43From 2 but that's completely fine because we already have that initial positions already configured set and ready
03:49So that 2 was a really bad idea and now that we know that that 2 was a really bad idea
03:54Everything should now be working again. So I'm gonna add an item move it to here add another item move it to here
04:01I'll move this here move this there click on replay
04:08Beautiful all that's left for us to do is to figure out that auto auto and manual mode
04:13So let's go back to that auto manual mode
04:15We already are looping through those elements
04:19All that we really have to do now is fetch that last position that last position that was defined in the end of a drag
04:26when it wasn't manual and
04:29Then connect it to where it is right now already
04:32So because when we're in manual mode
04:34It's not gonna do all this greatness and only we're in where when we are in a manual mode
04:40Then it's going to change that position
04:43So literally what we want to do is when we switch from is manual to not manual
04:47We want to loop through our elements and we literally want to check if our specific element and I'm just gonna save it as an
04:55Element or SVG or let's call it element just for the sake of consistency
05:00So I'm gonna go here and just create and wrap this loop around also. So
05:05there's no mistakes here or at least an attempt that there won't be and I'm gonna set my a elements and
05:12The position I to be that element and now it's time for me to basically test and see if there was a change
05:19now, how do I know if there was a change if my new position if my this that X if my X and Y positions are
05:27different from my
05:29Last P dot position X and Y then there was a change. So if
05:35This will not this if element dot X not
05:42Does not equal if it does not equal to the element dot last P dot X or
05:54We're gonna do the same thing for the Y
05:56Now if one of them is not the same it's time to animate it
06:05So I'm gonna go ahead here and I'm just gonna also create here very quickly an array
06:10so I'm gonna create our an a tweens and
06:13it's gonna be an array and
06:16I'm gonna go ahead here and
06:17If that condition happens and only if that condition happens and let me I could bring this up here
06:23So if it's different in any way or in an X or in the Y if it's not equal
06:30Then what we're gonna do is
06:32basically
06:34Whoo, what we're gonna do is basically animate it. So I'm gonna go ahead here and create a tween really quickly
06:40so I'm gonna create a tween light to
06:46from to actually and
06:48The first we're gonna animate that element. It's gonna take us
06:51We're gonna just hard code it to be 0.5 because we don't really know how long it should be and the next item that we want
06:58To set is basically from where do we want to animate it from where is gonna be the last point of reference?
07:04So it's gonna be from element dot last P and our second L item is gonna be our element
07:12Is gonna be a new object and I'm gonna set it to element X and by the way
07:17We probably shouldn't refer to that object directly because we don't want the tween engine to actually animate it
07:22So I'm gonna set here my X position to be coming from my element
07:26Dot
07:28last P
07:30dot X and we want to do the same thing for the Y and that was our starting position and
07:44Last but not least we want to set our X and Y positions now to go to the actual X and Y positions that we're actually
07:50in right now and that would be our element X and element Y and
08:01Okay, so hopefully we didn't have any errors here
08:04But let me just break things down a little bit. So it'll be easier to digest. Let me fix it a little bit
08:10so that doesn't need another comma and
08:14We could just push this a little bit back. So it's a little bit easier to look at
08:19Alright, so that's it. That should be everything we have to do. All that we have to do is also push our
08:25Timeline again just the way we did with our end drag
08:28So I'm just gonna push my timeline forward and then we could test it out and see if it's working
08:33now
08:34Theoretically what's gonna happen and I'm gonna after I add all these tweens. I also want to push each tween. So I'm gonna
08:41basically create another variable for one tween or
08:45Literally, just go ahead and push this whole thing
08:48So I'm gonna go ahead to a T dot push and I'm gonna just push all these tweens in all this tween in and
08:55Once we're done with the loop
08:57Once we're done with the loop once we're done with the loop
09:02Let me just clean things up a bit once we're done with the loop
09:05What I want to do is I want to call my timeline
09:07I want to add all these tweens in and I want to add my tweens right into that timeline in the
09:16Specific point in the timeline that we're in
09:19and
09:20Then then then well, we don't need we don't want to call this right now
09:23We all we want to call this actually right after we add all the items into the timeline. Okay, that's it
09:29I think our logic is that it should work I believe but you never know so let's go right in there
09:34Give it a try and see if it's working
09:36So first of all, I'm gonna just add items and I'm just gonna create one after each other
09:42Just add here like I don't know like us a grid of nine items. I'm gonna go ahead here
09:48Create a grid
09:51Now let's do a grid of six items. You don't have to wait too long
09:54So now that I've created the grid of six items first of all
09:57It's gonna all of them are gonna animate one after each other just the way we would hope for them to animate
10:02One after each other in the speed that it took me to create them. Perfect
10:06I'm gonna switch off auto that way I could start moving things around as as I please and I'm just gonna go ahead here and
10:13Just create here. Just let's say a triangle
10:16And I'm gonna switch them to auto so I could see right first of all element dot last P is undefined
10:26Let's see why though we're getting closer. We're getting warmer. That's for sure
10:30So element dot
10:33Element dot last P does not exist. Let's see. What is our elements? It's inside of our a elements
10:39So our a elements is pushing the SVG itself. We're push pushing the SVG itself
10:44We're not pushing the draggable object and literally if we take the actual draggable object itself
10:51Then it's gonna make our life a lot easier
10:53But if we take the draggable item itself, then we have to also refer to that item itself
10:59it within it so if I'm gonna push the drag item itself that I'm gonna just go here and
11:04when I'm actually referring to the element and I'm want to animate it if I'm gonna find it here one second and
11:12Instead of animating the element itself because we don't animate the draggable. We want to animate the elements target and
11:21If we're gonna pick the elements target then the element target were to return to us the SVG and all the rest here should
11:27Work because this is all this information that we're animating was information that derived directly from the basically the dragger
11:35Mythology, so if I save this and click on refresh, let's give this one more try
11:39So I'm gonna click on refresh and let's do this try to do this quickly at least one
11:44Two three
11:49Four I'm gonna need I'm gonna need six items to be able to create something interesting here
11:54Okay, and I'm gonna click on out of turn it off and I'm gonna go ahead and just create here a triangle
12:01Or an attempt to a triangle and I'm gonna click on play
12:09I'm gonna switch back to auto so I didn't get an error which is already a good sign
12:14And now I'm gonna just click on replay to see if I have my items first adding in one after each other
12:19And once the items are added in one after each other I
12:22Could now animate them all together
12:24I'm gonna click off to do manual again, and now I'm gonna just go ahead here and now create a let's say a line and
12:35I'm gonna switch to auto to capture it turn it back off go back in here create. Let's say an arrow
12:43Switch to auto switch back off
12:45I'm gonna go here and create now a little let's say a little mountain of items that are stacked one on top of each
12:51Other and that will be it and we are done with this lecture and two lectures
12:56It was a little bit long because we did a live recording and live recordings have mistakes. It's just part of the game and
13:03We fixed them. That's all that matters and that's exactly what's gonna happen to you as well as you're building things
13:08It's not that you're just gonna build it and it's just gonna work. This was recording was completely live
13:12We had no idea what's what was gonna actually happen in it and we I'm already really happy with it
13:18And we're gonna continue working with the timeline learning a few new things now with the timeline before we wrap up this chapter
