Hey there!
so I'm using this successfully to setup colliders based on a tilemap.
...
local tilemap = LDtk.create_tilemap(level_name, layer_name)
local emptyTiles = LDtk.get_empty_tileIDs(level_name, "Solid", layer_name)
...
if emptyTiles then
playdate.graphics.sprite.addWallSprites(tilemap, emptyTiles)
end
But I'm also using all kinds of collision groups which I usually setup like this (e.g.):
To iterate over return value of addWallSprites() and assign the groups retrospectively - with no success.
Since addWallSprites() is supposed to be shortcut for getCollisionRects() and then addEmptyCollisionSprite() (according to here I tried to do these steps manually - but I'm failing because neither tilemap nor emptyTiles is accepted as input for not being a tilemap but a table instead (but they seem to work for addWallSprites().
The problem in a nutshell: Cannot set CollisionGroups for spriteWalls.
Thanks for any tips in advance <3
(There is one thread that is marked as solved - but that solution I'd consider really as a worst case option.)
addWallSprites returns “an array-style table of the newly created sprites”. So what you can do is save this to a variable and then iterate on it. For example:
local wallSprites <const> = playdate.graphics.sprite.addWallSprites(tilemap, emptyTiles)
for _, aSingleWallSprite in ipairs(wallSprites) do
aSingleWallSprite:setGroups(COLLISION_LAYERS.BULLET)
aSingleWallSprite:setCollidesWithGroups(COLLISION_LAYERS.AISHIP)
end
Thanks for the reply! Unfortunately this is what I meant with my 'Tried No.1' attempt. I retried and it doesn't work. Also I'm don't know how to debug this and why it doesn't.
My only assumption is that the groups need to be set before the sprite is added to the world - which with this solution is to late.
I'm sorry this didn't work for you. My guess is there's a very specific problem related to something more global in your project. Try to printTable() different things (like the variables tilemap, emptyTiles).
Thanks @hteumeuleu for your support! Only by having the confidence in seeing your working code I noticed my case. And also I marked your answer as solution since it's solving what I asked in general.