2D Game — Tilemap & Tile Palette
Hello everyone!
In this post, I will demonstrate the process of creating terrain for your 2D game. Initially, I sourced a complimentary asset from the Unity Asset Store (https://assetstore.unity.com/packages/2d/characters/pixel-adventure-1-155360) and subsequently imported it into my project.
In order to edit this sprite and create multiple sprites from it, we need to adjust the labeled parameters shown in the image below.
- Sprite Mode: In ‘Single’ mode a sprite will use the entire image. In ‘Multiple’ mode Unity creates many sprites under the same asset in the project window.
- Pixels Per Unit: It’s expressing how many pixels from your Sprite fit into a unit in the Unity scene when the GameObject is scaled 1,1,1. In this situation we will set 16 and you can see in name of sprite that sprite is 16x16.
After adjusting the parameters, we will save the changes by clicking the ‘Apply’ button and proceed to edit the sprite by clicking the ‘Sprite Editor’ button.
In the following image, you can see that we have opened the ‘Slice’ dropdown and adjusted the labeled parameters.
When we selected ‘Grid By Cell Size’ for the ‘Type’ parameter, we entered the size by which to slice the sprite in the ‘Pixel Size’ field, which in this case is 16x16. We then clicked the ‘Slice’ button followed by the ‘Apply’ button.
After preparing our sprite, we now need to create a ‘Tilemap’ object in the scene. To do this, we will right-click in the ‘Hierarchy’ window in Unity, select ‘2D Objects’, then ‘Tilemap’, and finally click on ‘Rectangular’. In the following image, you can see a visual representation of the process.
After adding the ‘Tilemap’ object to the scene, we need to open the ‘Tile Palette’ so we can create the terrain in the scene. The following image shows the process of opening the ‘Tile Palette’ window.
In the ‘Tile Palette’ window, we need to create a palette by selecting ‘Create New Palette’, entering a name (e.g. ‘Terrain’), clicking the ‘Create’ button, and then selecting the folder where we want it to be saved.
After creating the palette, we need to drag the sprite that we previously edited into the ‘Tile Palette’ window and then select the folder where we want it to be saved.
And now, in the video below, you will see the final step of how to create a terrain visible on the scene by using all the steps we have previously taken.
And that’s it! I hope you were successful and found this tutorial helpful, just like I did.
Thank you!