Hello Guest

Author Topic: TileMap Layer offset  (Read 8986 times)

loofou

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
TileMap Layer offset
« on: August 23, 2012, 11:14:21 am »
Hello Everyone,

I don't know if I am just blind or stupid, but I can't find the layer offset function anywhere. In the 2dtk doc's tilemap tutorial there is a picture that shows layer offsets, but that feature seems to be gone in the newest version. I try to prototype my game using overlapping block tiles, so I need to set an offset in the Y coordinate for the upper layers to stack seemless to the lower blocks. Any guess where I would find the option?

I really appreciate any help with this, so thanks in advance!

Loofou

MooNiZZ

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 63
    • View Profile
Re: TileMap Layer offset
« Reply #1 on: August 23, 2012, 09:18:12 pm »
I've worked quite a bit with the tilemap, I see no reason why one would like to offset the layer in the y-axis, with the layer option you can move them in the Z axis and use each layer as "background" "foreground" etc,
you don't have to paint all tiles in a layer. Just skip the lowest part and start on row 2 if you want them to start higher up.

Please provide a picture since i cannot understand a possible scenario for this behaviour that could not be created using the current creation

edit: Some weeks ago i edited the Z-row for each row in each layer at buildtime, you could probably look at this and redefine it for your purpose. http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,447.0.html

edit2: Since i was curios about how i would do this i fixed it, right below line 285 in tk2dTileMapbuilderUtil.cs i added a y-value change
Code: [Select]
tilePosition.z += z;
tilePosition.y += layerid * 0.01f; // <-- added this, and each layers go up a bit higher. modify for your purpose :D
« Last Edit: August 23, 2012, 09:44:38 pm by MooNiZZ »

loofou

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: TileMap Layer offset
« Reply #2 on: August 23, 2012, 10:22:50 pm »
Problem is: I use an overlapping tileset for prototyping, so every layer needs an offset in the y axis to stack seemless to the lower tiles.

https://www.dropbox.com/s/5p2voko4lp2xzi9/LayerOffset.PNG

I have scribbled the needed offset in the picture above, so you'll get the idea of what i'm looking for.
The grass tiles are in layer 0 and the wooden blocks (and the blocks to the left) are in layer 1.

I don't know how to describe it any better, so I hope you understand what I mean :)

MooNiZZ

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 63
    • View Profile
Re: TileMap Layer offset
« Reply #3 on: August 23, 2012, 11:03:31 pm »
Check my code in the previous post as this do exactly as you want it to do, each added layer will put the tiles with an offset of 10 pixels,

Add this on line 285 in tk2dTileMapBuilderUtil.cs
Code: [Select]
tilePosition.y += layerid * 0.016f; // this is 16 pixels offset works for 32x32 tiles, take half the value of the tilemap pieces, if they're 64x64, add change the value to 0.032f and it should be fine.

if you only want one of the layers to do this, and not every layer >= 1, just put an if check
Code: [Select]
if (layerid == 1){
tilePosition.y += layerid * 0.016f; // this is 16 pixels offset works for 32x32 tiles, take half the value of the tilemap pieces, if they're 64x64, add change the value to 0.032f and it should be fine.
}

loofou

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: TileMap Layer offset
« Reply #4 on: August 24, 2012, 09:41:43 am »
Thank you! This works perfectly :D Nonetheless I would had preferred something more dynamic, but as I need this just for prototyping, it's not worth the trouble.

So thanks again for your time :)

MooNiZZ

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 63
    • View Profile
Re: TileMap Layer offset
« Reply #5 on: August 24, 2012, 09:48:25 am »
I haven't looked up any editor coding yet, therefore i couldn't provide you with a solid dynamic way of doing it.
But I'm glad it works the way you wanted :)

Just remember that if you upgrade the 2D Toolkit, your code will be overwritten so you'll have to add it again.

loofou

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: TileMap Layer offset
« Reply #6 on: August 24, 2012, 09:58:16 am »
I hope to have finished prototyping by then ;) But thanks for the warning.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: TileMap Layer offset
« Reply #7 on: August 25, 2012, 12:15:50 pm »
Thanks MooNizz for replying to these posts while I was away! Appreciate it.

@loofou - Doesn't this just work without any code changes if you go into "Settings > Tile Properties > SortMethod" to TopLeft? This should sort the tiles from top-down as opposed to the default bottom-up. A tiny offset is automatically added to each partition so it should just work fine in this case. An offset isn't necessary for the tiles themselves, as they will be sorted in the correct order.

loofou

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: TileMap Layer offset
« Reply #8 on: August 25, 2012, 02:28:19 pm »
They are sorted from top-left already :/ still needed the offset.

MooNiZZ

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 63
    • View Profile
Re: TileMap Layer offset
« Reply #9 on: August 25, 2012, 04:48:57 pm »
Thanks MooNizz for replying to these posts while I was away! Appreciate it.

Don't worry, I like helping out. So if I am able to do it, I will. :)
Got to find some time to the editor stuff and I'll mod tk2d for my own purposes. And help others on the forum :)
I love your work unikron! It will hopefully make me rich ;)