- Home /
How to make a 2D tile engine?
I'm quite new to using Unity, and I'm trying to convert my 2D C++ platforming game to Unity for a number of reasons.
The levels in my platformer consist of an arbitrary amount 32x32 tiles and levels are built with a custom level editor I also made in C++ where the user can paint tiles to build the level.
After using Unity for a little bit, I realized it's not immediately obvious how to create a tile system. My first thought would be to make a plane Prefab for each tile, and duplicate them all over the scene to create the level, however I think this would be highly inefficient for both performance and actually building the level (correct me if I'm wrong).
The only other way I can think of is manually rendering each tile (and creating my own tile editor somewhat like I did in the C++ version of my game, which had relatively good performance). However, I'm not sure how to go about doing this with scripting. In 2D C++, I simply draw a bitmap onto the screen with a single function call, but Unity involves cameras, textures, planes. (Draw all tiles to a plane and draw the plane?)
My current idea is this: Design a tile editor (extend unity with an EditorWindow script for example) to build the tile map data, and then create a script that calls Graphics.DrawTexture()
to draw each tile to the screen, ...however I think this would draw overtop of everything (like a GUI), wouldn't it?
Any advice on this would be much appreciated!
Answer by Eric5h5 · Nov 07, 2013 at 01:59 AM
You can use the Mesh class to create tiles. Meshes have limitations on the amount of vertices (~65K), so you may need more than one depending on the number of tiles.
I ended up just doing individual quads for each tile, and the performance seems to be good even with thousands of tiles on the screen (I wont need more than 150 or so on the screen), Unity is seems to be pretty good at optimizing the render calls with batching.
Answer by Taylord303 · Nov 07, 2013 at 06:43 AM
This link might be able to help you. He's doing something similar to what you're looking for, I believe.
Your answer
Follow this Question
Related Questions
Tiling textures issue 1 Answer
Tiling textures in Unity for Iphone? 2 Answers
Texturing Help 1 Answer
2D platform game, Tile 1 Answer