There is a killer among us
There is a killer among us, and it's you. No I'm not talking about the statistical probability that one of our viewers might be a killer, after all statistically speaking there is a possibility of that. Oh gosh that is scary. oh gosh... that is scary. In this lesson, we kill animations.
Video Transcript
00:00Killing is a horrible thing to do, but in programming when we say kill we actually mean to terminate a specific
00:07element and all of it's
00:09Everything that's going on in it, and that's exactly what we're gonna do
00:12We're gonna be killing tweens, and we're gonna show you the different ways of killing tweens
00:16Although we're only gonna look at it from within the timeline. You could also do these type of stuff directly to
00:22Tween light tween max and also there's a few methods that are helper methods that kill specific things like specifically like you have
00:29the tween light dot
00:32Kill tween of and then you could send that out kill tweens of and you could send the object itself
00:36So look into the documentation because we're not gonna look at every single way to kill things
00:40We're just gonna take the overview of killing things through the timeline itself
00:46There is a killer among us and statistically speaking
00:51There is a probability that one of the people watching this lectures could be a killer. Oh my god
00:58That is crazy spooky, but let's not think about killing as
01:03We talk about the kill method oh gosh
01:06What a dramatically horrible name to kill all right, so let's see what it is killing as as it sounds
01:12It's basically a very very
01:14Horrible thing to do and when you kill something you're literally
01:18Destroying it so I'm gonna go ahead here and just add here just a kill function and
01:24We'll play around with different kills in our kill function
01:28I'm gonna call it on kill and
01:32You could probably guess it that the name of the method is kill and by the way this method exists also in tween light tween max
01:38Timeline there is just no reason for us to talk about killing until now
01:42And it's not something I usually use on a day by day
01:45But you know sometimes you'll want to kill something so the first thing and the most simple thing is you just call kill
01:51It'll kill everything all the animations everything will just be terminated killed kaput
01:57If I do that and save that and just go and click on refresh
02:00And I'll just refresh my application add something move it around a little bit kill on kill it
02:06And then try to click on replay then that kill is gonna be very
02:11non effective
02:13But if I go ahead and I add to the kill a little bit more detail such as saying what do I want to kill?
02:20So if I go to my timeline, and I say all right. I want to kill every single
02:25animation of the X property
02:28Now what's gonna happen is it's gonna cycle through
02:31Every single item inside of the timeline and whatever is animating an exposition. It will kill that exposition
02:38It will not animate it no more, so I click on save here go back click on refresh
02:43add an item move it around a little bit and then
02:48kill and then
02:50Let me play
02:52We'll see that now our exposition is not animating only our Y position is animating now
02:58Let's go further into our kill so we saw that we could control the property but more over than that
03:03We could control even what are we killing so I could literally just go ahead here and say I want to kill both
03:09the X and Y animations, but I
03:13Only want to do it to our first item, so I'm going to go to my array of
03:18elements
03:20Let me just check what is inside that array of elements. It was the actual not the actual object itself
03:26So I need to send the object in
03:28So you know what position zero to the target?
03:31And I'm just gonna kill the X and Y animations all the animations of that specific object
03:37So if I go ahead save this and click on refresh and this time around I'm gonna add more than one item
03:43So I'm gonna add your item number one and item number two and I'm gonna move this here and there there and
03:50Then I'm gonna kill and then I'm gonna click on replay
03:54We're gonna see that one of the items is just not moving anymore because it's been
03:59Murdered so all of its animations that we were planning on animating are not animating no more
04:06Now if we want to kill all of the parts of the animation of that specific object
04:11All we have to do is just send that object without defining. What properties do we want to get rid of so in other words
04:19To kill all the parts of the animation related to this target
04:23Which is really what we just did right now
04:25I could go ahead and just send and say hey I wanna I'm not gonna even say what I'm killing because I'm killing everything
04:33No, I'm killing everything of this specific object and if I go ahead here and save this and
04:41Refresh here. I'm
04:43Gonna add two items. I'm gonna add go ahead here and move it move it move it move it kill
04:50Click on replay. We'll see that that one item that initial item won't be moving anymore because all of its animations were killed
04:58Contrary to the first part around where we're sending that first parameter with some information
05:02We could say only the X or only the Y or both of them and so on and so on
05:08Now beyond that if we wanted to kill more than one object for example
05:11What if we wanted to kill two objects?
05:13I could send it as an array and
05:16Literally say hey
05:17I want to kill object zero and I also want to kill object one
05:21And if I do that then both these animations I could send as many of them as I want
05:26So it's a very versatile function the kill function where item one will basically kill
05:32What properties do we want and if we don't say what then all of them will be killed if we send null
05:38then it will kill all of them and
05:40If we wanted to basically kill the entire animation of a one specific animation
05:46Then we would call the kill method now if we call the kill method to a full timeline
05:50It's not going to cycle through every object in that timeline
05:53It's not going to just it's basically not going to do anything
05:56But if we want to kill every single item then we'd want to approach them or call the clear function to clear all them
06:02Now always we're really going to do is kill the animation that we're actually in right now
06:07If we don't specify a deeper level inside
06:11So I go ahead and save this and just click on refresh here, and I'll add this I'm around three items and
06:18I'm going to just move all them and
06:21Move them a little bit more, and then I'm going to click on kill and I'll click on replay
06:27We'll see that only one of the three items is animating
06:30I think we're done with this lesson, and I think we're also done with this chapter
06:36So I hope you had a great time and in the next chapter. We continue diving deeper and deeper into the world of
06:43animations
