Cookie Cutter Bitmap Masking

Hi,

I’m trying to mask sprites using a cookie cutter technique on the sprite’s source bitmap, but I can’t figure out how to do it. Here’s my example bitmap that I’m using as a sprite’s image.

When two sprites overlap, I want to cut out the shape of the sprite from one of those two sprites. I can get the sprite to draw in all black (or all white) using…

pd->graphics->pushContext(_bitmap1);
pd->graphics->setDrawMode(kDrawModeFillBlack);
pd->graphics->drawBitmap(_bitmap2, 0, 0, kBitmapUnflipped);
pd->graphics->popContext();
pd->sprite->markDirty(_sprite1);

…but I want to cut it out and leave the area transparent. I thought there would be a “kDrawModeFillTransparent”, but there isn’t.

Is there another way to achieve this?

Thanks,

Rich.

I think you could render your cut-out to a texture the same size as the thing you're cutting out, then use image masks: Inside Playdate

Ahhh, right. I did come across image masks, but I’m using C, not Lua, so I didn’t think they were available to me. Turns out they’re called bitmap masks in the C SDK, not image masks. I think they’re going to do the trick. Thanks for the nudge in the right direction. :+1:

Yeah I think in general the terminology in Lua is image where it is bitmap in c

1 Like