Accessing wallSprites when using `sprite.addWallSprites()`


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, emptyTiles)

But I'm also using all kinds of collision groups which I usually setup like this (e.g.):


I tried:

  1. To iterate over return value of addWallSprites() and assign the groups retrospectively - with no success.
  2. 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> =, emptyTiles)
for _, aSingleWallSprite in ipairs(wallSprites) do

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).

You can have a look at a code of my mine (a port of Celeste Classic using LDtk) that has a very similar part of code: celeste/Source/Scripts/Objects/Room.lua at feat/ldtk · hteumeuleu/celeste · GitHub

1 Like

Thanks a lot! It's is actually very helpful to know that this should work. Also having a verified code sample is great.

Once I find the interference I'll post it here :slight_smile:

My bad. The problem was that I forgot to pass the collidergroups as a table.


worked for FINISH but failed for WALLS due to the nature of Lua it also didn't give a warning about too many parameters :slight_smile:

Solved by making a table out of it:


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.

Yay, glad you got this working!

1 Like