2D Sprite Sheet
In a nutshell, a sprite sheet is a way of packing images together as one image, which is then used to create animations and sprite graphics as it will use low memory and increase the performance of games.
Creating GameObject and Adding Components
- First of all, we need a GameObject in our scene. For this Right Click on the Hierarchy tab and select Create Empty.
- Rename the new GameObject. Here, we renamed it to Player.
- Select the Player GameObject and Go to the Inspector tab. In the Inspector tab, click the Add Component button. Choose miscellaneous -> Animator. Make sure to choose Animator nor Animation.
- Add another component, RigidBody2D. For this, click on the Add Component button and choose Physics 2D -> Rigidbody 2D.
- Now, in the Rigidbody 2D component, set the Gravity Scale to zero.
Importing the Sprite Sheet
- First of all, download the sprite sheet that contains all the frames of animation for a simple walking animation. A link is given below from where you can download: ken-sprite-sheet.png
- Right-click on the Assets and select Import New Asset...
- Browse to the sprite sheet image you downloaded and click the import button.
- Select this imported Asset, and in the Inspector window, change the Sprite mode option from Single to Multiple. Click the Apply button in the Inspector tab.
Now Unity will treat ken-sprite-sheet.png as a sprite sheet with multiple frames of animation.
Slicing Sprite Sheet
- Go to the Windows menu and select 2D -> Sprite Editor.
- Drag the Sprite Editor window and dock it. I docked mine alongside the Console tab.
- Click on the Slice drop-down, and here we can see that the options Automatic, Centre, and Delete Existing are default chosen. Some sprite-sheets have their images ordered in different ways. That is why there are a number of options to choose from.
Here I changed the Pivot value from Centre to Bottom. When you change the Pivot to Bottom means it sets the pivot point to the center bottom of the sprite, and slicing Type in this particular case should be set to be automatic.
- Then click on the Slice button. Unity has now separated all the sprites. Each sprite should have its own bounding box, clicking them provide information on each sprite and allow fine-tuning of sizes and pivot points.
- Now, click on Apply in the top right corner of the Sprite Editor window.
- Select the Player object in the Hierarchy tab and then in the Inspector tab click on Add Component button. Then select Rendering -> Sprite Renderer.
- Finally, you will be able to see all of your Sprites as an individual object in the Project -> Assets Folder.