Important Notice:

As of September 15, 2016, we no longer publish new courses on this website. We encourage you to use your Digital-Tutors credentials to sign in on Pluralsight where you'll find all new creative courses, skill tests and paths, 1:1 mentoring and more.
Manipulating sprites
See Details
Joshua Kinney

Pluralsight

Joshua Kinney
In this lesson, we're going to block in our level. All right, so to get started, let's go ahead and bring in our background element inside of our Environment Folder. And we're just going to drag and drop that into our scene. And you see that I have the scene view and the game view split here. And I'm going to work this way because it just seems to work a little bit easier whenever I'm trying to match up to the camera. So the background element that we've put in here, let's go ahead and reset its positioning. So I'm just going to left click on the gear, and hit Reset. And that's going to put that at 0, 0. From here we can come in and we could start to set up the camera, so that way it looks correct here. Let's go ahead and set up the game view for the camera, let's set this to the default 1280 by 720. This is one that I set up already. You can do it by clicking the Add button here. Give it a name, and then the dimensions that you want. So this is going to be the camera view that we see inside of our game view. All right? Before we start going any further, let's go ahead and bring in our foreground elements, or the ground elements. So inside of our environment, if we expand foreground, we have ground and all the rest of those that we've already split up. Let's go ahead and take the ground and drag that in. And here you can see the ground is pretty large compared to the background. Now, I could go ahead and re-size all of this if I wanted to, but I'm going to go ahead and just resize the background element. Because that's just going to make things a little bit easier. Instead of re-sizing the ground, and then the bushes, and all of the different props, let's just do one object here. Now the background could probably get away with being re-sized a little bit better, OK? So for this one, let's go ahead and take the background element, let's scale it, and let's go to two in both directions. And you can see that that takes that up quite a bit. And then what we can do from here is we can come in and we can adjust the position on the background element. So we're going to leave this at 0 on the x. Let's take the y and let's move that to 1. And actually we'll probably go up a little bit higher. Let's go up to 2. And then what we can do from here is we can take this ground element and we can move that into position right over here on the left side. Now I know that right here this is being cut off. And that's based on the camera's position. So if you select the main camera you could move that around if you want to. So I could pull this over, and you can see that that's where we're going to start out at. Let me go ahead and just reset that to 0, because I want to start out as 0. Let me pull the background element, let's pull that over to the right in the x direction. And let's do something like 12. Just hit Enter. Make it a nice even number, then I'll pull this one over. And let's take our camera and I'm going to pull that over to the right, just like so. So it's kind of the beginning of the level here. If we need to, we can pull the ground down a little bit further. So if you feel like you're seeing a little bit too much of that ground element, you could just pull that down. Now normally what I like to do is like to make these nice even numbers that are easy to remember. So negative 4, or negative 5, would be good as well. Either way is up to you. I'm going to go ahead and stick with negative 5 here. So now what we'll do is, we'll go ahead and we'll create the rest of our background elements here. And we can drag those out. You want to create the length of your level. But I know that I have a layout already set up here. So I'm going to go ahead and set up my ground elements first. So to do this, let's go ahead hit Control D. And that's going to duplicate that ground that I had selected already. And then I'm going to hold Shift, and then Control, and I'm going to left click and drag this off to the right. And you'll see here that they'll snap together. Now it's not going to snap up perfectly, it's overlapping a little bit, so if I hold down Shift all alone, I could just pull that out. And actually, that did snap pretty well, it was fairly close. Let's go ahead and leave it, let it snap like that. Might make things a little bit easier on us. So let's take, actually, you know what? Let's do this. Let's take this to 2, and let's delete that one. Let's hit Duplicate, or Control D. Hold Shift and Control. Left click and drag that out, and that will snap every 2 degrees there. Or every 1 degree there. And then we can just hit Control D, hold Shift and drag, and then we've got a nice even numbers there. And you can't really tell that it's not matching up exactly, but we're fairly close. Control D to duplicate, hold Control and Shift, left click and drag out until they snap to the end. Now we're going to do that to where we have a total of six of these. So I'll do it one more time. Control Shift drag, and there we go, OK? So that's our first stretch. Then we're going to have a gap. That's going to be where the player jumps over the gap and then goes on to the next stretch, OK? So let's select all of these. We're going to left click and drag. And I'm going to go down below the camera, so that way we're only encompassing all of the ground elements. You can also select the ground elements up here, by holding down Control, left-clicking on those. Or you can select the top one alone, and hold Shift and drag, or left click on the bottom one. And that will select all of those. It looks like, actually, let's try this one more time. Let's hit Control Z. It looks like I renamed one of those by accident. But either way, you could do it that way. Now from here, let's hit Control and D, and there we're going to hold Shift and Control. We're going to left click and drag that out. We're going to go all the way out to the end, and then we're going to go one, two, three, four, five, and six units out. And that's going to give me a nice gap there. So six units out of that. Then we're going to do it one more time, hit Control D. Hold Shift and Control, left click and drag, to where it goes all the way out to the end of that. Shift Control and then we're going say one, two, three, four, five, six, OK? All right, so now I've got three runs of my level. And then I'm going to kind of add an elevated view here. So I'm going to hold down Control, hit D. Hold Shift and Control, drag that up. And we'll do that to where we've got a value of 1 here. Hold Shift and D, and then drag it out, to where it comes out to about even to this edge. So we're going to make our character jump from here up to here, and we'll create a prop that they can use to jump off of up to there. And then we're going to have some elements back here. So I'm going to select all of these. Control D, hold Shift Control, and left click and drag that out. And I'm going to say one, two, three, four, five, six, that's a normal gap. Let's go out from the end of this right here. So I'm going to get that pretty even. And then I'll count one, two, three, four, five, and six, OK? And there we go. So now I've got my level laid out here, with the ground elements. Let's take the background elements, and I'm going to hit Control and D, duplicate that, and then we're going to hold Shift and Control. Left click and drag that out, and get that to snap fairly close there. The background may have a little bit of a harder time. So hold Control Shift, try to get that to snap, and it's not going to snap perfectly. So what we'll do is, we'll just hold Shift, so that it constrains it to the left and right. And we'll get that close. Select both of those, Control D. And then we're going to hold Shift, we're going to drag that out. Pull that out. And then we should do a couple more here. So Control D, hold Shift, drag that out. Just try to get it to butt up to the edge there. OK? And then one final one should do just fine. So I'm just zooming in, pulling that out to where it bumps up pretty close, and there we go. OK? So we could probably get rid of this one here. And then I'll just get rid of these ground elements. Because that's going to be the end of the level. Now you'll notice that my background elements are covering up most of my ground elements here. Now the reason that it's doing that is because we haven't set up any layers for these. And these are called sorting layers, whenever we're working with sprites. So to do this, first thing that we're going to do is, we're going to go to Layers. And you can see that I have some sorting layers already added here. I've got my Default Sorting Layer, I've got a Background, Props, Character, and Foreground. These I've already set up. But let's go ahead and show you how to create a new one. To do this, we're going to say Edit Layers. And then you could add in a new sorting layer by adding one in. And we're just going to say New Layer Five for right now. That's all you have to do. You can rename it to whatever you like. So if you want to name it Background or something like that, you're more than welcome to. And then all you have to do is go ahead and select your objects that you want to add to a single sorting layer. So these are my background elements. So I'm going to put those on Sorting Layer Background Here you can see that new Layer Five that we just created. So same process, just hit Background, and that's going to be placed there. Now once that has been placed, let's go ahead and add in the ground elements. So I'm going to select the top one, I'm going to hold down Shift, and select the bottom one. That will select everything in between. Let's put this on a sorting layer. And let's put this on Sorting Layer Foreground. And you'll see that those now pop up above the background. Now the reason that they do that is because of how we have the layers sorted. So let's go to Edit Layers. The layers are sorted this way. Let me go ahead to remove this Layer Five. All you have to do is highlight it and then minus. And then if you want to sort these, you can simply grab right on these double lines, and you can drag those and order them any way that you want. So the way this works is the bottom-most layer is the one that's going to be on the top. OK? So it's going to be drawn first. Or, excuse me, drawn last. Background elements, the furthest element to the back, is drawn first. And then so on and so forth. So background element is set to Layer 1, and that's in the second position behind Default. All right? So now that we have everything set up, we've got our background elements set, one other thing that I want to show you how to do really quickly is I want to show you how to lock layers. So I have my background elements on that background layer, and I'm going to be grabbing some different pieces. Because we're going to come in, and we're going to be doing props in the next lesson. So something that's really handy is to be able to lock your layers. Let me go ahead and lock my foreground layers as well, because I don't want to be moving those around either. So now that those have been locked, we can come in and you can see that I can no longer select any of these pieces right here on my scene view, OK? Now my main camera is being selected, but nothing else. Now I can still select them right here inside of our hierarchy. So that's something that you'll want to be wary of. So now we have everything set up, we have our game ready to go, now the only thing left to do is to go ahead and set up our main camera to where it looks correct in our scene. So this can be done by adjusting, with this camera selected of course, you can adjust this size. And you could say, all right, I want to go to six on this. Now we can move this over, and you'll see that all we see is the level. We get a little bit more ground in there, we can adjust this, we can pull that up or down, however we see fit. But adjusting that will do so. Another thing that you'll want to adjust is your clipping planes. In a 2D game, you're not going to have very long distances in the z. So what I'll do is, I'll set this up to 10. And what that'll do is, it'll kind of cut down on some of the memory usage. So it's just unnecessary have 1,000 there. All right, so everything else is ready to go here. We've got our camera set. So in the next lesson what I'm going to do is, I'm going to show you how to bring in props using 2D elements. So we'll get started with that next.
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