I'm developing a game and the character is divided into parts and I'm trying to make a code that makes the sprites not messed up when the character rotates using table.sort, the problem is that with or without this function it remains messy
part of the code that SHOULD fix the order of the sprites
local sort = function(a, b) return a.z < b.z end
table.sort(p.body, sort)
for i, b in pairs(p.body)do b.grid = newGrid(0, p.dir, 65, 65) end --this selects each sprite for each body part
I've been researching how to fix it for a while and now all I can do is ask on the love 2d website
table.sort is designed to work on sequences (tables with numeric indices), and you're using pairs() to iterate it, which suggests it's either not a sequence, or you should be using ipairs() instead.
pgimeno wrote: ↑Thu Dec 26, 2024 2:14 am
Hello, welcome to the forums!
table.sort is designed to work on sequences (tables with numeric indices), and you're using pairs() to iterate it, which suggests it's either not a sequence, or you should be using ipairs() instead.