Making a 2d game (Part 1)

I decided that I should probably look up some tutorials about making 2d games specifically in unity. I’ve made 2d games before in Java/python/Javascript/C# but in those games I usually generate the areas with maps of ints with each int corresponding to a specific tile. After you write the engine, generating maps is easy, but you can’t necessarily visualize it without some sort of map editor tool. Since unity has an awesome looking editor, I decided to check out how games made in unity use the editor to their advantage and learned some cool stuff. These posts serve as a way to reflect on the stuff I’ve learned and as a reference for later.

Tiles are created as prefabs.
In my previous approaches I’ve created a single plane to act as the ground and then generated objects on top of the plane. When programing in Java etc, this saved resources and helped to reduce the number of objects generated. However, it seems like unity is ok with generating a prefab for each tile on the screen. I’m not sure how light-weight the prefabs are, but, considering there were a lot of objects in my last project, the number of prefabs doesn’t seem to bog unity down too much so I’m going to try out this system and see how it goes.

Snap to grid feature.
This is the coolest feature I’ve seen in unity for a 2d game. When clicking on a prefab select Edit>SnapToGrid and it will show a dialogue box that lets you customize how the prefab will try to line up with the grid underneath. After that is selected, holding control will allow prefabs to snap to the next available space when moving them around. Using this approach I was able to create a small map very quickly. Looks like using this system will save a lot of time when creating tile-based maps.

Using game objects to organize.
Looks like empty game objects are used to hold all tiles related to maps. We did some of this in my last project, and it certainly worked, but I wasn’t sure if it was standard practice in unity.

Orthogonal camera.
Used this feature in previous implementations. makes sense for a 2d game, but I’d like to mess with the perspective camera to get a more picture book-y feel for a game like “The Woods”.

  • anguaji

    Hi there! Was wondering how you got on with this 2d stuff in unity? I’ve been trying unsuccessfully to make a small 2d roguelike in unity for weeks now and can’t get my head around it. Even though I’ve programmed it in lua/js before… Any help would be great!