Tiling sprites is a wonderful example of something that starts off relatively simple and then explodes into all kinds of interesting headaches.
In the beginning, you're looking up a set of UVs in a table indexed by some mask value.
In the end, you're debugging errors where one off by one error cascades into strange realms of indexing the wrong (unloaded) chunk with coordinates rolling over to positions that make no sense, looking up neighbours that look one way yet you end up drawing something completely different.
The suggest solution is an elegant and relatively common approach to what would otherwise be a naive series of nested 40+ if statements consisting of much swearing and sprite editing.
Don't be afraid of if-then chains. Smile and put the word REFACTOR in a comment nearby and move on to the next problem. Ship the thing! Perfectionism is overrated.
The low tile count simply comes from applying the dual grid approach popularized (if not invented) by Oskar Stålberg to a specific 2d perspective where tiles can be generated through rotations and/or flips.
There's a lot of explanation here but ultimately this is basically just the standard 16-tile set except assuming you can use rotations to deduplicate and don't need to allocate a tile for empty space. The latter makes sense for platformers (since your tiles likely represent objects that are supposed to be floating over some other background drawn another way) but not so much for, say, RPGs. (And the rotated tiles are often not great in RPGs, either.)
Tiled has some mode where you can paint the tile corners or/and edges to automatically insert tiles. When using only the corners to paint (and only a single terrain type) that would be equivalent to shifting the visual grid by a half tile trick, if I understand correctly?
Adding multiple types of terrain and also making it possible to paint the edges of course will add an explosion of possible tile types that are required. Looks like there is support in Tiled for optional automatic mirroring or rotations to add missing tile variations.
Does anyone know the history of auto-tiling in games? I know that Dragon Quest II (1987) had this feature for water tiles on the overworld, before it got backported to the North American version of Dragon Warrior 1.
I've never been a fan of dual grid, and personally prefer the rpg maker approach of using 5 sample tiles and then chopping up and recombining them to make the 47 tiles needed for what I believe is called "blob tiling".
This only works because this guy's tiles can be rotated without looking weird and he's on modern hardware that can freely rotate sprites with little cost. If your tiles are shaded or have patterns that look different when rotated then it does not work for you. If you are working on a game for the Nintendo entertainment system then it won't work either because you can't just rotate a tile.
11 comments
[ 3.2 ms ] story [ 26.8 ms ] threadIn the beginning, you're looking up a set of UVs in a table indexed by some mask value.
In the end, you're debugging errors where one off by one error cascades into strange realms of indexing the wrong (unloaded) chunk with coordinates rolling over to positions that make no sense, looking up neighbours that look one way yet you end up drawing something completely different.
The suggest solution is an elegant and relatively common approach to what would otherwise be a naive series of nested 40+ if statements consisting of much swearing and sprite editing.
Seems to be getting the hug of death.
Adding multiple types of terrain and also making it possible to paint the edges of course will add an explosion of possible tile types that are required. Looks like there is support in Tiled for optional automatic mirroring or rotations to add missing tile variations.
https://doc.mapeditor.org/en/stable/manual/terrain/