@tdebock
Thanks for your input!
I’m sure that hardcoding part of the walls as “back”, and another as “front” and inserting the player inbetween would work as long as you stay inside a rectangular room. But what if you walk outside the room and step in front of the “front” wall? You’d get the character hidden under the wall. What I’m saying is the walls need to sort dynamically with the player depending on where the player stands. Hardcoding some layers as front / back doesn’t solve the situation in my opinion.
The same for any objects (trees etc.), you can’t say which tree is “front” or “back”. As you walk around the tree, that aspect changes, if you step in front of the three, it must be behind you, if you step behind the tree, it must be in front.
When I was coding my own C++ iso engine years ago, the solution was pretty straightforward and much simpler. I made the player part of the “objects” layer (where I had walls / trees etc.). Then I just sorted everything to draw from back to front. If the player moved to a different tile I would resort. That is the only sane approach as far as I’m aware. With the C++ Cocos I saw people were using vertexZ to achieve this kind of thing. They’d set the layer to vertexZ “auto”, then set the proper Z for the player to “fit in”. That made sense at least. But there’s no access to “vertexZ” from TypeScript, based on what I saw at least.
Yeah, I was trying to do that initially, because it’s what I would do in my engine. But unfortunately - (like I mentioned earlier), it seems you can’t even do that All tile layer nodes have 0 child nodes. It’s just a single node in the Creator IDE rendering itself as one big thing. When I query # of child nodes of the layer node from code, it says 0. So I’m not even sure how to “add character into the layer”, however problematic that might be.
The only solution how to get anything into a layer seems with this:
http://docs.cocos.com/creator/api/en/classes/TiledLayer.html#settiledtileat
So I’d need to have a special tile with player sprite, which I would then erase (if at all possible) by setting a tile to null or some kind of empty tile, and then set the player tile at a different position lol. But that is incredibly messy even if it works, it would appear that the player sprite is “skipping” and I don’t think I could animate that sprite.
The C++ solution with setting Z (or vertexZ) seemed good, but there’s no way I found to affect vertexZ from TypeScript. Here’s one of the many threads describing the solution:
https://discuss.cocos2d-x.org/t/isometric-vertexz-problem-with-sprite/27037/4
There was additional transparency issue, lol…but lets ignore that. I’m hoping I’m really missing something fundamental and I don’t need to write my own TMX parser, when there’s one already available I’d need one of the following:
- Have tiles “exposed” as nodes so I can insert sprites “inbetween” (affecting the graph draw order?)
- Or, have the ability to at least change the “vertexZ” of nodes like people could in C++, or some alternative to that. Of course, the tiles would need to use that as well. So then when I say “player.vertexZ=10”, I’ll get part of the tiles rendering “behind”,and part in front. When I change players position, I’d change simply players Z and everything would render correctly.