Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Unity 2D tiled maps


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 SonicD007   Members   -  Reputation: 461

Like
0Likes
Like

Posted 20 June 2014 - 04:09 PM

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?



Sponsor:

#2 metaldev   Members   -  Reputation: 109

Like
2Likes
Like

Posted 21 June 2014 - 09:33 AM

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, 21 June 2014 - 09:34 AM.


#3 Seanba   Members   -  Reputation: 151

Like
1Likes
Like

Posted 26 June 2014 - 10:50 AM

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



#4 WunderStrudel   Members   -  Reputation: 156

Like
1Likes
Like

Posted 26 June 2014 - 11:28 PM

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.



#5 Eruadan   Members   -  Reputation: 257

Like
1Likes
Like

Posted 28 June 2014 - 08:18 PM

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();
        }





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS