I have been a web-developer for the past 6 years, and I’m new to game development. I am actually trying to do a prototype of topdown A-RPG (like hammerwatch). The first step for me is to render a map with two layers (ground and 1st floor), and the possibilites of:
Going behind the first floor
Colliding with the walls surrounding the first floor
Having a stair that makes me switch to the first floor layer
So the collision objects on 1st floor should not bother my character if he is on the ground, and same for ground collisions if I am on 1st floor. Here is a picture : image
For now I created the tilemap with two layers, and the tilesource, so rendering is fine. However even if I play with the Z-positions i can’t get my character to go under the second layer…
Any help is appreciated ! And sorry for my bad english !
Sorting tilemaps is a bit tricky and requires you to customise your render script. Giving a detailed description would be quite lengthy, but if you are willing to do some digging in the documentation and doing a little trial and err or your self, in short, what you need to do is:
Create a new material based on the builtin tilemap material
Change the tags to be called something else than “tile” - such as “tile_overlay”
Set the material of your overlay tilemap to the new material
Add a render predicate to your render script with the tag from the new material
Render that predicate after the particle_pred
The even more tricky part will be when the player should be above the overlay - but give me a holler when you have solved the first one and I will write a part two of this…
I’m going to dig on this right now ! I already looked at the materials and custom renderer a bit, and it makes me wonder how will I deal when I have a dynamic number of layers later during the development (say ground, big arch that is 3 layers high, and a platform that moves under it) ? But yeah i’ll take the time to think about it later I’ll get back to you ASAP !
You will need to do some creative stuff to get that working. One way would probably be having the overlay tilemaps as empty tilemaps and copying from tilemaps with tilmap.get_tile and tilemap.set_tile as the player ascends or descends levels. We do something similar in Hammerwatch Coliseum to build semi random tilemaps.
Yeah I thought of something like that, but this approach seems more like a “zoom-in / zoom-out” gameplay, where as the player switches to the upper level the camera has a zoom effect to slide to the level. I don’t think it will fit my approach, as I won’t have a lot of levels. I’m thinking more of something like this where I can go either under the bridge (in the water) or on it, so the whole area would be rendered, and no dynamic additional map rendering would be required ( I don’t know if i’m making it clear )
EDIT Managed to create the overlay material, now I am able to go under the “rocky-like” tiles which are in an overlay tilemap !
I am not talking about any zoom effect, simply a way to dynamically choose which tilemap(s) will be drawn above the player and which will be drawn below.
In the simple example image I would make the bridge a sprite and sort it with z-positioning depending on wether the hero is walking, but assuming there are more complex scenarios where tilemaps are required, this is how I would do it (I think):
Create a tilemap with evertything except the bridge. Make sure the water and the ground have different collisions.
Create another tilemap containing the bridge with a different material (lets call it “overlay”) that has both the “tile” tag and another tag called “overlay” that can optionally be rendered after the tile predicate
Add both tilemaps to a go or collection and align them
When the hero walks the “upper level” I would not draw “overlay” so the hero would appear to walk above the bridge
When the hero walks the lower level I would draw “overlay” and the hero would appear to walk below the bridge
I would also have different collision logic depending on level, where the hero would not be able to walk on ground if on first level, and not on water if on second
I think that about covers it
EDIT: I should probably mention this approach is not the “copy between tilemaps”-approach I talked about earlier. That is only needed if the levels are dynamic.