Hello Guest

Author Topic: Possibility to change Y offset of Layers in TileMap?  (Read 4584 times)

regnared

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 27
    • View Profile
    • Mah website
Possibility to change Y offset of Layers in TileMap?
« on: November 20, 2012, 01:03:58 am »
When I change the Y offset of a certain layer, the second the game runs the Y offset is reset to 0. Is there an option to turn this off? (only for that particular layer)

The reason I am using y offset, is so I can use a single tile for small objects that will be placed on the bookshelves but also use it to place it on the floor.

Example:

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Possibility to change Y offset of Layers in TileMap?
« Reply #1 on: November 20, 2012, 09:32:50 am »
Hmm.. interesting. Never thought of this use case.
It is easy enough to patch in though -
in tk2dTileMapBuilderUtil.cs, look for this line:
               layer.gameObject.transform.localPosition = new Vector3(0, 0, accumulatedLayerZ);

and then change the y there for layerId == 1.

regnared

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 27
    • View Profile
    • Mah website
Re: Possibility to change Y offset of Layers in TileMap?
« Reply #2 on: November 20, 2012, 05:57:27 pm »
Thank you for the code. :)

I went up with using :

Code: [Select]
                    layer.gameObject.name = tileMap.data.Layers[layerId].name;
                    if (layer.gameObject.name != "top objects")
                        layer.gameObject.transform.localPosition = new Vector3(0, 0, accumulatedLayerZ);
                    else
                        layer.gameObject.transform.localPosition = new Vector3(0, 12, accumulatedLayerZ);

Since I have 3 layers for the level, they would of all been offset by 12 pixels.

Would it be possible to acquire the X and Y local values of the layers position and use them in? I have seen in the code that there is a Z value ( tileMap.data.Layers[layerId].z ), X and Y would be mighty useful if ever someone has many layers. This way I would not have to hardcode any values in and the code would be kept to one line, clean and beautiful. 

Code: [Select]
         layer.gameObject.transform.localPosition = new Vector3(tileMap.data.Layers[layerId].x, tileMap.data.Layers[layerId].y, accumulatedLayerZ);
This way the layers would always stay put, where they are needed. I tried browsing in the code for a way to acquire the data, I guess for now it would have to be with prefabs or going the hardcoded way?




unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Possibility to change Y offset of Layers in TileMap?
« Reply #3 on: November 21, 2012, 06:56:28 pm »
It won't be in the next update, as this is slightly more involved for a generic solution, but I'll look into it for the following update.

regnared

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 27
    • View Profile
    • Mah website
Re: Possibility to change Y offset of Layers in TileMap?
« Reply #4 on: November 21, 2012, 07:59:57 pm »
Oh wow. Thanks a lot for that. :)