📜 ⬆️ ⬇️

Work with sprites (Unity3d). Part II

Introduction

In the first part of the article, we looked at importing sprites into Unity3d and some features of import.
In the same article, I want to talk about SpriteSheets.

SpriteSheets as they are


SpriteSheets greatly facilitate the work with sprites and animation. This feature allows you to split the sprites in a single file into separate animation frames. Too abstruse and many letters. Below is an illustration.

Gif

In this example, thanks to SpriteSheets , sprites are stored in a single file for animating running, flying, waiting, etc. So it really makes work easier.
Let's now drag such a sprite onto the stage and see what happens.
Gif

After adding it to the scene, it became one big sprite, and this is wrong and it does not suit us.
In order to tell Unity that we have more than one file in the file, we need several to refer to the Sprite Mode field in the Inspector, changing the value from Single to Multiple there, thereby telling Unity that this is not one sprite, but some . Illustration.
Gif

Having done this, we will see that there is a new button Sprite Editor , which we will use. Clicking on it in front of you will open a window allowing you to "cut sprites." Here you need to open the context menu using the Slice button, in which you will have access to all the settings for “sprite slicing”. To facilitate the thought process illustration.
Gif

Let us consider in more detail the possibilities of this menu.
The first thing we see here is the type of "splicing" sprites. If we keep the Automatic value and click Slice, Unity will cut all the sprites, just by taking the minimum possible number of pixels. This does not always suit us, because if we apply this method in our particular case, the sizes of all the sprites will be different, and this will lead to an unacceptable "jerky" animation. Here is an example of unsuccessful automatic "slicing".
Gif

Although if the sprites are the same in size, which is also often the case, this feature will save time.
Now consider the manual "cutting" sprites.
In the same menu, we change the Automatic value on the Grid , after which we specify the height / width in pixels and also click Slice.
If during the "cutting" sprites by hand, you have empty sprites (they are formed!) , Do not pay attention to them. They will not affect your project in any way.
Gif

Again, automatic cutting of sprites is a useful feature, in fact, saving a lot of time and nerves. Therefore, try whenever possible to use automatic "cutting". Once again I will repeat how to determine which type of function to use. If the sprites are the same or differ slightly, then use the Automatic function, otherwise the Grid.
Looks like the same manual flight animation:
Gif

That is all folks.

')

Source: https://habr.com/ru/post/240107/


All Articles