Level Generator


All levels happens on the same unity scene! 

The Level Generator was created based on Brackeys's video teaching how to create a level editor, with some changes because he made a 2D platform and I made a top-down 2D game. Also, the tile assets can be founded in the Devian Art site made by 7soul1.

There is a Game Object called Level Generator that through a small pixelated image constructs each level with prefabs. When an image in unity is marked as readable, in code, if imported as a Texture2D element, each pixel can be read and have characteristics extracted as the pixel's color in RGBA. So with a function that loops inside each image's pixels, you can determine where to instantiate each object in the scene. Prior, a class is made to match each prefab tile (all instantiated objects are prefabs) to the color that will represent him. An added as a public array in the Level Generator code.

When calculating the position to instantiate the prefab, it is really important to pay attention to the pixel per unit size of the images and the pixels' position in the image. About the pixel per unit size, it is recommended to all of them be the same, but not obligated. For example, the door is supposed to have the size of almost 3 by 1 unit, a bit smaller actually, so to arrange this, it had a different pixel per size. Also, you don't have to instantiate one prefab per color, to have a floor behind the characters I needed to initiate first the floor and them the character. 

A future project is to simplify the color code. For example, to make the walls were used 12 different colors because depending on where the wall is, it changes the sprite. To make it simpler I could use 1 color and through code analyze his position looking at which are, or if there are, other pixels that are closed. Also, create a plugin to rapidly change the sprite using graphs instead of lines of codes and public variables. And maybe make it works together with Unity's tiles set. 

The image under this paragraph is the color code that I used to make a level. Feel free to try to make one and send me through my twitter or comment on your ideas and thoughts about the post. Right after is the image used to create the first level and it has a size of 33 x 16 pixels., in real proportions is this one: .

Color Code


  

Files

WebVersionBuild.zip Play in browser
Jun 08, 2020

Leave a comment

Log in with itch.io to leave a comment.