Allowing getCollisionRects() to use invalid tileID

When setting up a tilemap, it is allowed at the moment to set a tileID to 0 (even if this is not a valid ID). It will be shown as fully transparent as expected.

The issue is that when passing the list of empty IDs in getCollisionRects(), it seems the tileIDs need to be a valid reference to the tileset even though the tileID might be used in the tilemap. As a result invalid entries in the tilemap will be always solid when we use addWallSprites().

It is quite typical in a level editor to not always set all the tiles in a tilemap so that would be nice to also be able to do that for playdate games using tilemap and still use the SDK collisions.

Here a little test case:


local tiles = {}
for y = 1, 24 do
	for x = 1, 40 do
		local tile = 2
		if x > 20 then tile = 0 end
		if x==1 or x==40 or y==1 or y==24 then
			tile = 1

		table.insert( tiles, tile)

local tilemap =
tilemap:setImageTable( "tiles" ) )
tilemap:setTiles( tiles, 40)

local level = )
level:setTilemap( tilemap )
level:moveTo( 0, 0 )
level:setCenter(0, 0)
level:add() tilemap, {2, 0} )

function playdate.update()
	local collisionRects = tilemap:getCollisionRects( {2, 0} )
	for index, rect in ipairs(collisionRects) do*10, rect.y*10, rect.width*10, rect.height*10)

And the tiny tileset:


Filed! Sounds pretty straightforward, should be an easy fix.

1 Like

Please fix this. I am also running into this issue.

1 Like

Hey @dave

Is it possible to get an update on this?

Dan says it looks like the fix for emptyIDs for tilemap get repeated - #6 by dan also fixes this. Update coming soon! :sweat_smile: