Page 1 of 1
Help with tiles and sprites
Posted: Fri Sep 30, 2022 7:48 am
by darkfrei
Hi all!
I've made some system, where the placed tiles have several sprites, depends on neighbour tiles. So if two tiles of same type are near to each other, then it looks like they are placed together, no border between them. The spritesheet looks like
https://github.com/ProjectET/Terraria-T ... r/TTGS.png (but not the same).
Can you please help me why the edge of the tile cannot be correct processed and the better sprite for this tile will be chosen?
- 2022-09-30T09_47_55-Untitled.png (7.45 KiB) Viewed 3028 times
- 2022-09-30T09_51_17-Untitled.png (7.62 KiB) Viewed 3024 times
Re: Help with tiles and sprites
Posted: Fri Sep 30, 2022 3:26 pm
by darkfrei
Ok, it was hardcoded limit in the cycle.
- 2022-09-30T17_26_22-Untitled.png (17.55 KiB) Viewed 2986 times
- 2022-09-30T17_24_59-Untitled.png (15.58 KiB) Viewed 2986 times
Re: Help with tiles and sprites
Posted: Fri Sep 30, 2022 4:14 pm
by pgimeno
Not sure what you're into, but for creating outlines around groups of identical tiles, I'd use a bitmapped system: 4 bits for the edges and 4 bits for the corners, total 8 bits. Not all combinations are valid, though: there are a total of 47 combinations of edges and corners, and where there's an edge, there are no corners. so it can be solved with a sparse table.
Here's the mapping of bits to corners and edges that I've chosen:
- bit-distribution.png (2.52 KiB) Viewed 2973 times
And here's the zoomed tileset with a gap between the tiles for better visibility:
- border-tiles-white-gaps.png (990 Bytes) Viewed 2973 times
A corner dot in the top left (for example) is necessary when:
- the tile on the top left of the current one is air;
- both the tile on the top and the tile on the left are ground.
Similarly for the rest.
An edge at the top (for example) is necessary when the current tile is ground and the tile on the top is air, and similarly for the rest.
- example-borders.png (1.77 KiB) Viewed 2973 times
Re: Help with tiles and sprites
Posted: Fri Sep 30, 2022 4:15 pm
by pgimeno
Sorry for the double post but 3 attachments are the maximum.
Here's the project.
The system can be trivially extended to curved
edges corners, by changing the tileset.
Re: Help with tiles and sprites
Posted: Sat Oct 01, 2022 9:21 pm
by darkfrei
pgimeno wrote: ↑Fri Sep 30, 2022 4:15 pm
Sorry for the double post but 3 attachments are the maximum.
Here's the project.
The system can be trivially extended to curved
edges corners, by changing the tileset.
Thanks! The format 0x00 is not very familiar for me, but I can understand the logic of it.
But how can I use several variants of the same type of tile? It's easy to make just one predefined, but several of them in the same scene is not so easy to me.
Re: Help with tiles and sprites
Posted: Sat Oct 01, 2022 9:37 pm
by pgimeno
darkfrei wrote: ↑Sat Oct 01, 2022 9:21 pm
Thanks! The format 0x00 is not very familiar for me, but I can understand the logic of it.
0x is the prefix that indicates that a number is in hexadecimal notation. I used hex because there are no binary literals, but hex to binary translation is trivial, so hex is the closest you can get to seeing the binary digits with reasonable readability.
darkfrei wrote: ↑Sat Oct 01, 2022 9:21 pm
But how can I use several variants of the same type of tile? It's easy to make just one predefined, but several of them in the same scene is not so easy to me.
Maybe using more bits. Bits 8 and 9 could be the bits of four variants. So, if the variant is a number from 0 to 3, add 0x100 if the variant is odd, and add 0x200 if the variant is >= 2. Or simply add the variant number times 0x100.
Or you could draw them in two layers: background and edges. The edges would follow the rules in my example while the backgrounds would have any variants you want. Or combining both, so you can have variants of edges too.
Re: Help with tiles and sprites
Posted: Sun Oct 02, 2022 5:03 am
by ReFreezed
pgimeno wrote: ↑Sat Oct 01, 2022 9:37 pm
I used hex because there are no binary literals
Actually, in LuaJIT there are, in the form of 0b11001.
Re: Help with tiles and sprites
Posted: Sun Oct 02, 2022 10:03 am
by pgimeno
Oops, thanks! Good to know.
Re: Help with tiles and sprites
Posted: Sun Oct 02, 2022 5:03 pm
by ReFreezed
It doesn't seem to be documented anywhere as far as I've seen, for some reason. I feel like LuaJIT's documentation is lacking in general. :/
Re: Help with tiles and sprites
Posted: Tue Oct 04, 2022 4:02 pm
by pgimeno
ReFreezed wrote: ↑Sun Oct 02, 2022 5:03 pm
It doesn't seem to be documented anywhere as far as I've seen, for some reason. I feel like LuaJIT's documentation is lacking in general. :/
I've just checked and it seems that it only works in 2.1, which is not out of beta yet, so that may be a reason for it not to be documented.
In 2.0, 0bXXX literals don't work.