2D Toolkit Forum
2D Toolkit => Support => Topic started by: regnared 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:
(https://dl.dropbox.com/u/16537765/2d_toolkit/y-offset_example.jpg)
-
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.
-
Thank you for the code. :)
I went up with using :
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.
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?
-
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.
-
Oh wow. Thanks a lot for that. :)