Join Adam Crespi for an in-depth discussion in this video Slicing in the Sprite Editor, part of Unity 4.3 Essential Training.
- View Offline
After you've imported in your sprites and tagged them as single or multiple, you can start to slice them up, slicing up a sheet of multiple images into different sprites for use. I'll pick my background image, and the first thing I'm going to do is to change the pixels to units. I'll put these at 512 so that my 2048 image becomes four meters wide once I bring it into my scene. I'm going to put the pivot down to the bottom as well and this way, if I need to register something against that pivot at a known coordinate, I can do that. I'll also change the format from compressed down to true color.
Make sure when you're using sprites, you're running true color so you don't compress your sprites and see artefacts or have odd issues when you're trying to slice them. Now I'll click Apply and then I'll do the same with my car's 2D before I slice it. Pixels to units are set at 512. It's a multiple sprite and true color. I'll apply it and go into the Sprite Editor, which I can get to either here from the Inspector, or by choosing Window and Sprite Editor from the top menu. In the sprite editor, we can see our image and the transparency is shown by our grey grid.
We have a couple of different ways to slice this. We can drop down on the Slice menu on the top left and choose Automatic or Grid. This will do a best guess for automatic based on the alpha channel of the image. I would run into some issues with it because the alpha channel on my cars just touches that pink bottom bar and so I may get some very odd slicing in here. Grid as an alternate lets you set out a slice based on a pixels size. And this way, if you know you've gridded out your spreadsheet for example, and can slice evenly along that multiple, you can slice a whole sheet of sprites very quickly.
I'm going to leave this alone and do a manual slice instead. I'll start out with the white car as this is the one I'll animate to knock into the green car next to it. Once I lay out a slice, a menu pops up asking do I want to trim this, and set that pivot. I'll trim it to size down around that sprite, and put the pivot down on the bottom. Then I'll pick the next car and do the same. Again, trimming and putting the pivot on the bottom. Now look at the next cars down. I'll take these three yellow and other color cars Trim them and put their pivot at the bottom as well.
And finally, the solo green car next to it. For the bottom cars and the pink car they sit on, I'm going to trim them all at once. And this way it's a fixed bottom object the other cars will stack on to. I'll select everything in here, all six of the bottom cars, plus that bottom border. In the Sprite menu, I'll choose Trim, and put the pivot down at the bottom. Now my sprites are sliced. I've got three unique cars, one group of three and a group of six with the bottom. And I can apply these and order them as I need. I can even make them lap over each other to create parallax by putting them on different sorting layers, I'll click Apply. And unity will finish and I can close the sprite editor. And now in the Cars 2D, I can see I've got all five sprites. They can be named if we need, and we can drag them uniquely into the scene to start to build up our 2D elements.
- Designing the game
- Creating and transforming objects
- Importing and configuring models and textures
- Setting properties in the Inspector
- Creating the terrain geometry
- Building materials and adding shaders
- Creating GameObjects
- Exploring physics
- Animating objects
- Lighting the scene
- Creating 2D game elements
- Adding special effects