playdate.graphics.setStencilPattern(level) only works one line in 8

Mac Simulator, Version 1.9.3 (133541)

When I call playdate.graphics.setStencilPattern(level) I get what looks like level of the pixels in some rows and no pixels (all off, as if stencil were black) in the other rows. It seems to be one row in 8. For example, using playdate.graphics.setStencilPattern(1) gives horizontal stripes. playdate.graphics.image:drawFaded works, so I'm able to work around this, but it'd be better if the stencil dither worked as in the docs.

For the benefit of anyone else trying to use this before it's fixed, here's the monkeypatch:

local ssp = playdate.graphics.setStencilPattern
function playdate.graphics.setStencilPattern(...)
    local args = {...}
    if #args <= 2 then
        level = args[1]
        ditherType = args[2] or playdate.graphics.image.kDitherTypeBayer8x8
        local b = playdate.graphics.image.new(32, 32, playdate.graphics.kColorBlack)
        local w = playdate.graphics.image.new(32, 32, playdate.graphics.kColorWhite)
        playdate.graphics.setStencilImage((w:blendWithImage(b, level, ditherType)), true)
    else
        ssp(...)
    end
end

(It's obviously not good for performance since it's making those images every time but it's good enough for my use.)

1 Like

known bug & related: Masking sprites? - #14 by dave

should be fixed in the next release.

1 Like

Not fixed in Version 1.10.0 (135263) I'm afraid. playdate.graphics.setStencilPattern(1) still gives horizontal stripes.

Oof. Don't know how that one slipped through. I assumed it was a recent regression but I went back and it's always been broken. :confused:

But no more! (Well, once the next update rolls out..) And since I factored together the argument handling for gfx.setStencilPattern() and sprite:setStencilPattern() the latter now has the row1, row2, ... form as well.

2 Likes

I think this is still an issue in 1.11.0 unless i'm misunderstanding something. Is level meant to be between 0 and 1?

Sorry, we've got a huge backlog of merge requests right now. I've learned my lesson, won't say "fixed in next update" any more. :frowning: But this should be in 1.12? :crossed_fingers:

2 Likes

no shade!! just raising that it's still weird. I also think the documentation could be a little clearer about what's acceptable for the level argument!

4 Likes