Help with tiles and sprites

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Help with tiles and sprites

Post 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
2022-09-30T09_47_55-Untitled.png (7.45 KiB) Viewed 2350 times
2022-09-30T09_51_17-Untitled.png
2022-09-30T09_51_17-Untitled.png (7.62 KiB) Viewed 2346 times
Attachments
ter-tiles-01.love
(5.27 KiB) Downloaded 66 times
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Re: Help with tiles and sprites

Post by darkfrei »

Ok, it was hardcoded limit in the cycle.
2022-09-30T17_26_22-Untitled.png
2022-09-30T17_26_22-Untitled.png (17.55 KiB) Viewed 2308 times
2022-09-30T17_24_59-Untitled.png
2022-09-30T17_24_59-Untitled.png (15.58 KiB) Viewed 2308 times
Attachments
ter-tiles-02.love
License CC0 (no license)
(5.9 KiB) Downloaded 63 times
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Help with tiles and sprites

Post 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
bit-distribution.png (2.52 KiB) Viewed 2295 times
And here's the zoomed tileset with a gap between the tiles for better visibility:
border-tiles-white-gaps.png
border-tiles-white-gaps.png (990 Bytes) Viewed 2295 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
example-borders.png (1.77 KiB) Viewed 2295 times
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Help with tiles and sprites

Post by pgimeno »

Sorry for the double post but 3 attachments are the maximum.

Here's the project.
border-tiles.love
(1.43 KiB) Downloaded 74 times
The system can be trivially extended to curved edges corners, by changing the tileset.
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Re: Help with tiles and sprites

Post 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.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Help with tiles and sprites

Post 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.
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: Help with tiles and sprites

Post 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.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Help with tiles and sprites

Post by pgimeno »

Oops, thanks! Good to know.
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: Help with tiles and sprites

Post 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. :/
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Help with tiles and sprites

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 43 guests