Sign in to follow this  
SonicD007

Unity 2D tiled maps

Recommended Posts

Is there any easy way to create tiled maps in unity 2D?  If not, I would like to use tiled to create a map in the tmx file format to then import that tmx file into unity.  I realize I'll probably have to create an importer for unity to be able to understand the file but I'm not sure how to create custom importers for unity 2D.  Is it only available in the Pro version?

Share this post


Link to post
Share on other sites

There are already a bunch of tools that can import from Tiled to Unity listed HERE :

Unity 3D
  • Orthello Pro (2D framework) offers Tiled map support.
  • Tiled Tilemaps library by Karnak Games adds support for Orthogonal TMX maps to Unity, with automatic collision detection.
  • Tiled To Unity is a 3D pipeline for Tiled maps. It uses prefabs as tiles, and can place decorations dynamically on tiles. Supports multiple layers (including object layers).
  • Tiled2Unity exports TMX files to Unity with support for (non-simple) collisions.
  • UniTMX imports TMX files into a mesh.
Edited by metaldev

Share this post


Link to post
Share on other sites

Hi Sonic, if you're working in Windows then I think Tiled2Unity is the only Tiled-to-Unity pipeline utility that easily allows you to add complex colllisions to your maps. That's why I wrote it. :)

 

I've made it easy to use and I've got more tutorials coming soon to my blog. In any case, give it a try and let me know what you think.

 

http://www.seanba.com/introtiled2unity.html

Share this post


Link to post
Share on other sites

Making a tile engine in 2D is very easy, especially  using unity. (: 
Basicly you only need 3 main functions. 

generateTileMap() {

    This Function is gonna "generate" the values, to fill into a 2D array (public int[][] foo = .....). so basicly the information you need for the different block types.

 

}

 

buildTileMap () {

    in here you are gonna go through your 2d array "foo" and place a different texture, decided by the value at it's cords in the 2d array. 

 

}

 

generateCollision() {

    This is basicly where you make the collisions, also decided by the value value at it's cords in the 2d array. for example. 

    

    for (int x = 0; x < blocksX.length(); x++) {

         for ( int y = 0; y < blocksY.length(); y++) {

               

               if (Block[x][y] == 1 ) { // Dirst Maybe

                   Collider();

               } else if (Block[x][y] == 2) { // Water maybe

                  then execute whatever you want to happen when in the water. 

 

               }

         }

    }

   

}

 

And just so it is said!! d: 
The code above is NOT! working code. it is only for example purpose, i'm not really sure if it is half java and half c++, havent really written in c in a while. So dont copy paste any of the code, it surely wont work. (: 

Hope you make it work, if not i think i have an old project laying around, where i build a 2D tile engine you could take a look at. you can just pm me. 
Sincerly WunderStrudel.

Share this post


Link to post
Share on other sites

Do you want to do anything specific with your tile map? Are these tiled sprites used for animation? Are these terrain? Different types of tile maps *should* be implemented differently... Here is a sprite tile map example from an old C# project of mine.

private Bitmap SelectSprite(string imageloc, int x, int y)
        {
            // Create a Bitmap object from a file.
            Bitmap myBitmap = new Bitmap(imageloc);

            // Clone a portion of the Bitmap object.
            Rectangle cloneRect = new Rectangle(x * 32, y * 32, 32, 32);
            System.Drawing.Imaging.PixelFormat format = myBitmap.PixelFormat;
            Bitmap cloneBitmap = myBitmap.Clone(cloneRect, format);

            return cloneBitmap;
        }

Here is it's usage:

 public void DrawCharacter(PictureBox CharPictureBox, PictureBox MapPictureBox)
        {
            SetSpriteBMP(SelectSprite(GetSprite(), 1, Direction));
            CharPictureBox.Show();
            CharPictureBox.Location = new Point(X_Location * 32, Y_Location * 32);
            CharPictureBox.Parent = MapPictureBox;
            CharPictureBox.Image = GetSpriteBMP();
        }

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this