2D Toolkit Forum

2D Toolkit => Support => Topic started by: Sundaerae on April 20, 2013, 05:32:24 am

Title: Using Tilemap Editor for Top Down RPG
Post by: Sundaerae on April 20, 2013, 05:32:24 am
So I'm a newbie trying to use the Tilemap Editor (Beta) for my just-for-fun RPG project and so far I know that you can add depth between layers, and adjust the height.
here's my question:
1. How do I put a non-tiled sprite, such as trees, to that editor? If I put it on the collection, the tilemap editor and the pallete will go awry. If I cut the tree into tiles, I had to paint it per tiles everytime I need a tree.

2. How do I auto-create layers? I want to have a layer 0  for row 0, layer 1 for row 1, and so on until I have I have <tilemap.height> layers so I can put trees on layer 20, put a doghouse in front of it at layer 21, and then another tree but a bit to the right, several tile below it at layer 24

3. how do I know the 'tile coordinate' of the current tile that I hovered with mouse pointer on editor?

thanks a lot for the reply
Title: Re: Using Tilemap Editor for Top Down RPG
Post by: unikronsoftware on April 20, 2013, 11:57:38 pm
1. About the arrangement of tiles in the palette - the next tilemap update will let you rearrange tiles as you need them to be. Keeping the tree within the tilemap is probably the best thing to do, if just for the automatic collider merging, etc.

2. Why would you want to do that? Maybe I'm missing something obvious, but this sounds like a very expensive way to do things...

3. Very similar to how tis done in the editor - refer to tk2dTileMapSceneGUI.cs
Code: [Select]
Plane p = new Plane(tileMap.transform.forward, tileMap.transform.position);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float hitD = 0;
if (p.Raycast(r, out hitD))
{
float fx, fy;
if (tileMap.GetTileFracAtPosition(r.GetPoint(hitD), out fx, out fy))
{
int x = (int)(fx);
int y = (int)(fy);
// you know what tile you're hitting now
                         }
}
Title: Re: Using Tilemap Editor for Top Down RPG
Post by: profanicus on June 29, 2013, 05:24:13 am
This thread is slightly old but since it's relevant to what I am doing I thought I'd post comments here rather than start a new one. I'm also attempting an angled top-down game with a camera view much like an old jrpg, Phantasy Star IV for example:
(http://i.imgur.com/pIzkDmR.png?1)

In point 2, I think Sundaerae is trying to deal with sorting by having a layer for each row. By setting each row of tiles at a different height your characters can pass in front/behind tiles that overlap other tiles (like trees) easily, if the characters Z are also based on their Y position.

I'm trying to do something similar - have a layer for flat terrain and on top of that a layer for props and structures that moving objects like characters should be able to pass behind and in front of. At the moment I am using freely placed sprites for these structures, and a script on each that sets their Z value based on the Y position.

However, it's somewhat unwieldy compared to just painting tilemaps so I was wondering if there is another way ... is there another method you can think of, or perhaps a place in the mesh gen code where I can add an offset to the Z position on a row-by-row basis for a particular layer?

Another question: accessing layers through code - I see that layers are int based, but in the UI the layers all have string identifiers. Is there a way to tell which layer is 0,1,2 etc if I have given them all readable names, and no longer have numbers there? Are they numbered by their order in the inspector maybe?

edit: Ok I see the layer number can be inferred from the tk2dTileMapData asset, by the ordering of the array in the inspector.
Title: Re: Using Tilemap Editor for Top Down RPG
Post by: unikronsoftware on June 29, 2013, 06:03:43 pm
If you're doing something  like this - use alpha tested (cutout) shaders for the foreground objects and save yourself a LOT of trouble. Have all the objects sorted by depth correctly - i.e the ones further down vertically should be closer to the camera. Use a consistent formula for mapping y -> z, and use the same formula for the characters z location, and it should Just Work. You'll have characters going behind objects, etc.
Title: Re: Using Tilemap Editor for Top Down RPG
Post by: profanicus on June 30, 2013, 12:34:24 am
Hmm that's pretty much what I said I am already doing (lots of foreground sprites with a script that maps their y->z on startup).

I was thinking that painting them on a layer would be a lot easier to manage than masses of gameobjects, and 'simply' having each mesh row on that layer offset it's Z when built would give the same result. Like the existing Z separation for layers, but for each row within a layer.

Could you point me to the right place to make a change like that, or is it totally unfeasible?
Title: Re: Using Tilemap Editor for Top Down RPG
Post by: unikronsoftware on June 30, 2013, 11:43:41 am
tk2dTileMapMeshBuilder.cs - RenderMeshBuilder.BuildForChunk. The sprites there are added in correct sorted order. All you need to do is increment z per row (currentPos.z).
And in tk2dTileMapBuilderUtil.cs - CreateRenderData, make sure each chunk is positioned with the correct z offset so the chunks line up. Should be obvious what you need to do after #1 is done.
Title: Re: Using Tilemap Editor for Top Down RPG
Post by: profanicus on June 30, 2013, 01:52:22 pm
Excellent!

I added a "z offset per row" field to the Settings/Layers inspector so I can control it per layer, and it seems to be working wonderfully. Cheers.
Title: Re: Using Tilemap Editor for Top Down RPG
Post by: Amefuri on December 29, 2013, 06:13:59 am
Excellent!

I added a "z offset per row" field to the Settings/Layers inspector so I can control it per layer, and it seems to be working wonderfully. Cheers.

Sorry for dig up this thread, I face the same problem here,
I am able to make tile z sort by y row in tk2dTileMapMeshBuilder.cs but what I want is to make it sort in their local layer or any other solution. So it will not corrupt with other layers. how did you do it?

Thank you,