Important Notice:

The Digital-Tutors site will soon be retired and your access will be turned off - but don’t worry, you can still enjoy all your favorite Digital-Tutors content on Pluralsight (plus thousands of additional courses, skill assessments, paths and more). You can log in to Pluralsight with your Digital-Tutors credentials, as well as update your password at any time on Pluralsight. Please contact us with questions or concerns: support@pluralsight.com.
Using sprite sheets for animation
See Details
Joshua Kinney

Pluralsight

Joshua Kinney
In this lesson, we're going to show how to use sprite sheets for animation inside of Unity. All right, so this final lesson I wanted to take and show you how to use sprite sheets for animation. And I really saved this for last, because this is really, really great. If you have followed along with the 2D racing game series course, you'll find that there was a lot of work involved to use the sprite sheets, and you get those to animate. There was so much code that had to be done, a lot of research went into that. And you're just going to look at this now and you're really going to appreciate this. I know that I do, I mean I had to figure out how to get the card to animate, and get the sprite sheet to cycle properly. So we're just going to make this nice and simple. Let's say that in a platform or game like this, the player needs to collect coins or something like that. And we wanted an animated coin in our scene. The way that we would go about doing this is by creating an empty game object, An just like we did with our character. And we're going to call this coin. And on coin, what I'm going to do is I'm going to go ahead and create an animation. So to get started with this-- actually before we create an animation, what we want to do is we want to add a sprite renderer to this, so that way I can actually see it in the scene. So I'm going to Add component. Let's go to Rendering, and then Sprite renderer. And I'm going to go to Sprite, and I'm going to click on this, and I'm going to go to Assets, and I'm going to use the spinning coin. I went ahead and I imported that in. It's in your environment folder. So spinning coin, and you'll see that that comes in. Now the spinning coin itself, if we take a look at that, it's just a single image. Now this is a sprite sheet. And each sprite is a different frame in the animation. It's drawn out. The reason that you would want to use a sprite sheet instead of the set-up that we did for the character here is that you want 2D assets to look as though they belong to a 3D world. So for example, the zombie is set up in kind of like a paper doll fashion, to where his arms move in a very linear way. They spin and they rotate in a very linear way. But the coin here, we want it to spin along the, in Unity case, in the y-axis. So it's going to kind of have this foreshortening effect, to where it spins around to where we could actually see the side of the coin, and then it comes back around, and then back out to the flat side here. And so this would be a great reason that we would want to use a sprite sheet. Now normally, you wouldn't do characters like this. You would do characters to where they're in a sprite sheet, it's very manageable, less pieces to work with, and it will keep your memory size low. But I wanted to just show you how to push the animation tools to the extreme with a character, and then we'll follow it with a sprite sheet on something like this. So first off, we need to go ahead and split this up. So let's go to our Sprite mode, and let's change that to Multiple. And then we're going to open up our Sprite editor. And what we want to do is we want to slice this up using the grid. Now the pixel size that we're going to be using for this is going to be 256 by 256. Now I already know that value. If you don't know that value, you want to get with your artist and see how they set up their sprite sheet. Normally, whenever we create sprite sheets, we set them up into limitations, to where each grid is a certain pixel size. You can actually take a look at volume two of the 2D racing game series, and learn how create sprites just like this. So here we have that, pivots are already set. You'll hit Slice and then Apply, and close that down. And you'll see that has now been sliced apart here. Now let's go ahead and select our coin. And let me move that over here, and you can see that it's now a single coin, instead of all six of those. So now what I want to do is I want to create the animation. And this is the really great part, because it goes so fast. First off, let's select our coin, let's create a new clip/ And I'm going to put this inside of my anime clips folder. Let's go ahead and just call this spin, and hit Enter. We're on the spin animation. Let's go ahead and take are samples down. Let's go down to 24, and make this a little slower. And then all we have to do at this point is expand our spinning coin, select all of the frames of that animation, and then drag and drop that right here in your timeline. It's going to create your key frames for you automatically. You could actually zoom in on that, and see what each one of those key frames represents. So this is key frame one, that's the first image, the second, third, fourth and so on. So now all I have to do is simply hit Play, and you can see that working right inside of Unity. No more messing with scripts, trying to get those to read all the way out to the end of the sprite sheet and then going to the next row if absolutely needed. It's so simple now, so great, such a great tool, my favorite feature of these 2D additions to Unity 4.3. So it's really as easy as that. We could turn that off, turn off record. We have our coin in game. We could put this right inside of here. Let's put the coin on a sorting layer, let's put it on the prop sorting layer. And all we have to do is hit Play now, and you could see that right inside of the game, animating as it should. We've got our player with this idle animation. We can press the D-key, and it moves forward, and it walks. We've got our movement. We don't have any collisions on the coin of course, we can spin him around, go the other direction. And now it would be a matter of creating things like the jump animations. Creating the jump functionality. Getting into where we create collisions for the coins, to where we could collect that. You'll create a HUD All of these things can be done using the 2D tools right inside of Unity. And personally, I think it's just such a great addition. 2D games are really, really fun. I enjoy making them, I love playing them. I hope that this course has given you a grand idea on how to use the 2D tools inside of Unity 4.3. I would like to see what you guys start coming up with. We're not going to see a last of this game here, as we have plans to create more games, and expand on this, and create this even further. This is just to give you a taste of the 2D tools, and get you started working on your own projects. So in the meantime, I'd just like to see what you guys come up with. Hope you guys had fun in this course, and I'll see you guys next time.
In this series of training we will discuss the major components of working with the 2D features in Unity. We'll start off by learning how to set up a 2D Unity project. Then we'll learn how to properly import and slice our sprites. After that we'll learn how to manipulate sprites by blocking in a simple platform level and also learn the importance of Sorting Layers.

Then we'll jump into the real fun by assembling, parenting and animating a character. By the end of this tutorial, you will have a better understanding of working with Unity's 2D features.
Introduction and project overview
1

Introduction and project overview

 
00:45
Setting up a 2D Unity project
2

Setting up a 2D Unity project

 
13:05
Manipulating sprites
3

Manipulating sprites

 
14:03
Setting up props
4

Setting up props

 
13:35
Slicing the character
5

Slicing the character

 
13:57
Parenting the character
6

Parenting the character

 
09:25
Creating the colliders
7

Creating the colliders

 
11:10
Creating the idle animation
8

Creating the idle animation

 
17:31
Blocking in the walk cycle
9

Blocking in the walk cycle

 
11:50
Finishing the walk cycle
10

Finishing the walk cycle

 
08:06
Setting up the animations
11

Setting up the animations

 
04:49
Scripting the movement
12

Scripting the movement

 
12:55
Using sprite sheets for animation
13

Using sprite sheets for animation

 
07:48