[MUSIC] We've seen little glimpses of places where I've used this thing called an SKAction in our development of breakouts so far. And in this lecture, what I would like to do is elaborate on what's going on with SKActions. And all the different ways in which you can use it to manipulate sprites and to manipulate the environmental factors in your game. So at High-Level what SKActions are are a powerful way to schedule events in your game. The iOS operating system handles the timing of the events and it can handle sequences of events. It can handle doing something when the event is over. And your primary job, if you're going to use SKActions is to decide what the event is, design the interaction, and then trigger it. And then iOS handles the very specific timing of having it all occur in your game. So SKActions is an idea. It's a bundled concept for doing several different kinds of actions. And it's almost like a timing mechanism for making all these things happen. So the motivation can be seen in this clip from the game Plants vs Zombies 2. And as we watch this game, what I want you to notice is all the different ways in which things are moving and which sounds are playing and which effects are happening on the screen, just the number of different things that are happening. I'm pausing it and then we'll start again. Here we go. [SOUND] So the general idea with this game is that monsters are arriving from the right and trying to get to your base on the left and you have to setup a defense against them and there are kinds of different powers and rules and things that are involved. But look at the different animations, sounds and effects that are going on. And they're all precisely timed. When a monster gets hit, the animation for the monster changes so that it becomes one of monster being damaged, something like that. So as we look at that, we look at that as an idea of why it might be helpful to have some support for animations and for events. That's kind of the reason why SKAction is so powerful and why you might want to use it in a game that we have. So in that specific example, there's just an enormous amount of visual and auditory activity. There're lots of independent sprites moving around and animating just in that example features sort of to explain to you how much was going on. You had enemies, for example these zombies, they had animations associated with them and they had a movement associated with them. We had environmental objects, there was this lily pad, and that lily pad is slightly animated and has a role in the gameplay. We had things that were basically game objects, like the sun icon that bounced around and gave you power, or this leaf icon that bounced around and gave you a power up, or this bullet which is being fired a pea which should be fired from one of the plants. Those are all game objects of some sort, that were being animated and moved kind of independently from everything else. There are all kinds of visual notification. For example, your score was up there and getting animated. There was this low tide warning at the beginning, and then I don't know if you noticed it but down at the bottom, there were these power-up icons that were flashing at the same time. So on top of that, you can also have particle systems. Now, there was one sort of electrical effect that was going on during the game. I don't actually think that was a particle system but we'll use it as a stand-in for a particle system. You have water moving. You also had a whole bunch of ambient sounds that were playing, so listen to all the sounds that were playing. [SOUND]. You have a background music. You have the sound of things being fired. Weapons being fired. You have the sound of things being hit. You have groans from the zombies, whatever that is. [SOUND] Each one of those sounds is an action as well that's being triggered by some kind of an event. Now it's not that these categories I put on the left are some kind of exhaustive or meaningful categorization of the different elements in the game. I'm just sort of categorizing them on the fly here to show you just what a wide range of kinds of events and animations and sounds were all being triggered in a very specific order. You don't want the zombie to appear to be damaged until it's been hit by the object and you don't want the sound of the zombie dying to be played until the zombie's actually dying, so there's a lot going on. So we can use the SKAction class in order to. To create those actions, create that effect, SKActions are associated with SKNodes meaning that nodes are the ones that are the place in where the actions are executed. So in order to run an action, what you need to do is you need to design the interaction. You know this is just a bullet that says you have to think about what you're going to do. And you need to think about it and that think work is actually more important than writing the code. Once you know what you're doing, then you can write the code to implement it. To implement it, you instantiate an action using an initializer. You set the parameters of the action, and then you attach it to a node. You run it by attaching it to a node. And then from that point on, iOS takes over and executes it for you. Most SKActions have durations. They take some period of time. That's because they involve an animation or a sound. And once you start that action, iOS manages the action but also the duration that's involved. Some of the actions aren't specifically things that happen on the screen but they're things that affect the playback of the actions or the duration of actions or the grouping of actions. So, for example, you can trigger a sequence of actions that's going to happen one after another and you can tell iOS to manage that and it'll take care of the whole management of the sequence. You can also ask it to handle a group of actions for you. If you want several actions to occur at once. Some of the actions are reversible, so you can ask to undo an action. And some of the controls within SKAction enable you to change the speed of the animations, or the speed at which they're playing. Right, including repeating an action as what another thing that you're able to do. So here's some categories for them. SKActions can affect the movement of nodes on the canvass. They can affect the rotation of the nodes on the canvass. They can change the animation speed. They can scale an object, larger or smaller. They can fade in or fade out objects. They can change the visual appearance of a sprite, its color or. The texture that's being to apply it. You can change the properties of the physics body that's attached to a node. You can play sounds, you can remove a node from the hierarchy causing it to disappear from the screen. Or you can alter the node hierarchy in different ways. You can even perform inverse kinematics, which is something that we're not going to get into but it's a way of trying to get a complicated object to arrive at a particular pose. Without saying specifically how it's going to get there. So, here's for code check, we're going to leave it to the next lecture because it's a little bit of a long code check, where we're going to walk through it. But, as we prep for that, in summary, SKActions are a sophisticated animation tool. And iOS developers can use them to trigger sequences of actions in their game. SKActions can also include compound actions and arbitrary code. All right, that's the idea. Now in the next lecture, let's dig in and take a look at how it can actually get implemented in an app. Thanks. [MUSIC]