sprite:overlappingSprites behavior change in 0.12.0

Just upgraded to SDK 0.12.0 and noticed a deviation in behavior from 0.11.0 in the lua api’s sprite:overlappingSprites function. Previously, sprites were returned if either sprite collides with the caller (based on groups), whereas now only sprites the caller collides with are returned. Here is a minimum example to reproduce this behavior:

local gfx <const> = playdate.graphics

local spr1 <const> = gfx.sprite.new()

local spr2 <const> = gfx.sprite.new()

local output = false

function playdate:update()

    if not output then
        local overlaps1 = spr1:overlappingSprites()
        local overlaps2 = spr2:overlappingSprites()
        print("API version is "..playdate.apiVersion())
        print("There are "..#overlaps1.." overlapping sprites for spr1")
        print("There are "..#overlaps2.." overlapping sprites for spr2")
        output = true

On 0.11.0, this outputs:

22:46:30: API version is 1100
22:46:30: There are 1 overlapping sprites for spr1
22:46:30: There are 1 overlapping sprites for spr2

However, on 0.12.0, this outputs:

22:45:58: API version is 1200
22:45:58: There are 1 overlapping sprites for spr1
22:45:58: There are 0 overlapping sprites for spr2

The changelog for 0.12.0 includes:

  • improve default behavior of sprite collision groups

which might mean this is intentional, especially considering the docs include language like

taking the sprites’ groups and collides-with masks into consideration.

when describing the behavior of overlappingSprites. Still caught my off guard. I fixed my code by simply updating the collision mask for the sprites involved.

This got me, too.

You’ll need to add spr2:setCollidesWithGroups({1})

From 0.12.0 Groups are now mandatory for collisions to happen.

I just wanted to note that they’re not quite mandatory - if you haven’t used groups or collides-with groups at all, your sprites will still collide with each other.

1 Like

Oh, that’s nice! All or nothing, sort of.

I need to read the latest docs.