sprite.allOverlappingCollisions includes touching

image
These collision boxes are next to each other, not overlapping, however they are returned in as overlapping by sprite.allOverlappingCollisions.

Do you have code that demonstrates this? In the console in your screenshot it looks like the allOverlappingSprites array is empty, but maybe there is something I'm not seeing.

I created an example to reproduce what it looks like you're doing and it does not look like it's detecting any collisions.

If you run the following, it should output: #collisions: 0

import 'CoreLibs/sprites'
local gfx <const> = playdate.graphics

class('Box').extends(playdate.graphics.sprite)

function Box:draw(x, y, width, height)
	local cx, cy, width, height = self:getCollideBounds()
	gfx.setColor(playdate.graphics.kColorWhite)
	gfx.fillRect(cx, cy, width, height)
	gfx.setColor(playdate.graphics.kColorBlack)
	gfx.drawRect(cx, cy, width, height)
end

local function addBox(x,y,w,h)
	local block = Box()
	block:setBounds(x, y, w, h)
	block:setCollideRect(0,0,w,h)
	block:addSprite()
end

addBox(0, 0, 32, 32)
addBox(32, 0, 32, 32)
addBox(0, 32, 32, 32)
addBox(32, 32, 32, 32)
addBox(64, 32, 32, 32)
addBox(0, 64, 32, 32)
addBox(64, 64, 32, 32)

local collisions = gfx.sprite.allOverlappingSprites()

print("#collisions: " .. #collisions)

function playdate.update()
	gfx.sprite.update()
end
1 Like

You're correct. It's 100% my not reading my own code. Sorry Dan, thanks helping though, I would probably have carried on not reading it properly if you hadn't replied.

Here's some code to prove it:

import "CoreLibs/object"
import "CoreLibs/graphics"
import "CoreLibs/sprites"

local pd <const> = playdate
local gfx <const> = pd.graphics

class ("Cell").extends(gfx.sprite)

function Cell:init(x, y)
	self:moveTo(x, y)
	self:add()
	self:setCollideRect(0, 0, 32, 32)
end

Cell(32, 32)
Cell(64, 32)
Cell(32, 64)

local overlappingSprites <const> = gfx.sprite.allOverlappingSprites()

print("collisions:  ", #overlappingSprites)
printTable(overlappingSprites)

function pd.update()
	gfx.sprite.update()
end

Will generate this:

Will output this to the console:

collisions:  	0
{
}

i.e. No collisions and an empty list of overlapping sprites.

1 Like