Is it possible to change the tileset pivot?

866 views
Skip to first unread message

Inocêncio Oliveira

unread,
Sep 17, 2014, 10:25:48 AM9/17/14
to mape...@googlegroups.com
I think by default the tiled map editor puts the tiles on bottom left side orientation. I have noticed that when I worked with two tilesets one with 32x32 and another with 16x16 and the result was the smaller tiles didn't stand on middle of the bigger tile.

This picture illustrates better:

Then the crystals doesn't stand on middle of the tile. Is this possible to change the tileset pivot? I'm using this great tiled map edit with Unity on my own, building my personal tool to read and render the maps. On Unity by default a texture picture pivot is on center.

Thanks in advance.

Michael Neel

unread,
Sep 17, 2014, 11:46:28 AM9/17/14
to mape...@googlegroups.com
If you want to mix tile sizes I've found the best way is to set the map to the smallest size used - this will give you the most placement options.  I don't think though (I could be wrong) there is a way to get the method you want - where a 16x16 tile would center in a 32x32 space in Tiled unless you set an 8x8 map tile size.  You could certainty make it so that Unity rendered it the way you want though without creating that small of a map tile size.

Related note - I've been working (slowly) on a Unity reader and rendered for TMX maps - open source, so you are welcome to grab any code for your game https://bitbucket.org/vinull/utiled

--
--
Tiled Map Editor mailing list
mape...@googlegroups.com
http://groups.google.com/group/mapeditor

---
You received this message because you are subscribed to the Google Groups "Tiled Map Editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapeditor+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Michael C. Neel (@ViNull)
http://www.ViNull.com

Thorbjørn Lindeijer

unread,
Sep 17, 2014, 12:11:31 PM9/17/14
to mape...@googlegroups.com
Actually, if you always want to center these 16x16 tiles in the 32x32 grid, just apply a tile offset of 16 pixels for x and -16 pixels for y. You can edit the tile offset in the Tileset properties.
 
Regards,
Bjørn

Inocêncio Oliveira

unread,
Sep 17, 2014, 2:58:57 PM9/17/14
to mape...@googlegroups.com
@Michael Neel

Thanks, Mike, I appreciate that, I'll check your project. The differences I have seen so far that you generates a mesh and material stuff for the maps, mine project I just take the spliced tileset and I build the map with sprites without the need to create mat or mesh. I don't know if my way is a proper pattern or not.

Yeah I have figured that. I can just put the base map to work with a smaller tile size and it makes the map works more precisely, this is one way out.

@Thorbjørn Lindeijer

Thanks for your comment, Bjørn. I have a idea: since Unity works by default with a center pivot for textures and images, I just make it explicit if someone else need to use a centered tile.

Michael Neel

unread,
Sep 17, 2014, 3:10:08 PM9/17/14
to mape...@googlegroups.com
If you are working with Unity sprites, you can change the pivot point.  I currently import tiles on object layers as sprites, and on tile layers as a mesh.  The reason is performance, every sprite is an object for the garbage collector and will crash the scene if you add too many.

Here is an early commit that just used sprite objects - https://bitbucket.org/vinull/utiled/src/ee07aee5721d4f825748a6657da7e689debbb52a/Assets/UTiled/Editor/TiledMapReader.cs

Also, Bjørn has a much better solution with the offsets than mine (and you would think after having to handle all the ways a tile can be offset in two importers now it would have occurred to me!)

Mike

--
--
Tiled Map Editor mailing list
mape...@googlegroups.com
http://groups.google.com/group/mapeditor

---
You received this message because you are subscribed to the Google Groups "Tiled Map Editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapeditor+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Inocêncio Oliveira

unread,
Sep 22, 2014, 10:31:20 AM9/22/14
to mape...@googlegroups.com
Hi again, guys!

Sorry Bjørn to post this off-topic here, it is just to finish up this conversation.

@Michael

I have figured out how to get the tile position to make tiles at center or wherever I want to. In that process, we don't need to use the texture pivot as well.

Just use its rendered texture as parameter and you'll get the bounds and calculate it:

var sprite = tileGo.GetComponent<SpriteRenderer>().sprite;
var pos = tileGo.transform.position;
if (sprite != null)
 return new Vector3(pos.x + sprite.bounds.min.x, pos.y + sprite.bounds.min.y);
return Vector3.zero;

tileGo is a gameobject of a tile, then I take its SpriteRenderer, the position and get (in that case) the bottom left corner.

@Michael, have you tried to render a 300x300 map or bigger? Each rendered tile is a single tile or a mix of them? I'll take a look better on the way you do to use mesh and material, maybe it increases the speed of rendering.

I'm close to make my tilemap engine based on Bjørn's Tiled Map, usable to simple maps. I can give you more details if you want guys.

Michael Neel

unread,
Sep 22, 2014, 11:23:57 AM9/22/14
to mape...@googlegroups.com
I have a test map in the UTiled source that is 150x150 of the same tile repeated - this was enough to bring Unity to a crawl with each tile being a Sprite GameObject.

I had another game I made with Tiled and XNA that had a map size of 864x480 (and many layers) - this crashed Unity! Note I don't recommend making a single map that large ever - there were many more problems than just rendering it.

If you look into the mesh route, there is also a limit of 64K verts per mesh to be aware of. UTiled handles this by splitting a layer into multiple meshes. Using this method I was able to load the giant map just fine in Unity.

Mike

--
--
Tiled Map Editor mailing list
mape...@googlegroups.com
http://groups.google.com/group/mapeditor

---
You received this message because you are subscribed to the Google Groups "Tiled Map Editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapeditor+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages