Well, this most probably doesn't help, but this is how I do it in Lemmini:
// remove invisible pixels from all object frames that are "in front"
// for upside down objects, just create the upside down copy
if (o.upsideDown || inFront) {
for (int frame = 0; frame < spr.frames; frame++) {
imgSpr = ToolBox.createImage(spr.width,spr.height, Transparency.BITMASK); // get flipped or normal version
if (o.upsideDown) {
// flip the image vertically
imgSpr = op.filter(spr.img[frame], imgSpr);
} else {
WritableRaster rImgSpr = imgSpr.getRaster();
rImgSpr.setRect(spr.img[frame].getRaster()); // just copy
}
// for "in front" objects the really drawn pixels have to be determined
if (inFront) {
for (int y = 0; y < spr.height; y++) {
if (y + spr.y < 0 || y + spr.y >= bgHeight)
continue;
int yLineStencil = (y + spr.y) * bgWidth;
for (int x = 0; x < spr.width; x++) {
if (x + spr.x < 0 || x + spr.x >= bgWidth)
continue;
// now read stencil
int stencilVal = stencil.get(yLineStencil + spr.x+ x);
int stencilValMasked = stencilVal & Stencil.MSK_WALK_ON;
boolean paint =
drawFull || (stencilValMasked != 0 && drawOnVis) || (stencilValMasked == 0 && noOverwrite);
// hack for overlap:
int id = Stencil.getObjectID(stencilVal);
// check if a different interactive object was already entered at this pixel position
// however: exits must always be painted
// also: passive objects will always be painted
if ( inFront && spr.type != SpriteObject.TYPE_PASSIVE && spr.type != SpriteObject.TYPE_EXIT && id!=0 && id != n)
paint = false;
// sprite screenBuffer pixel
int imgCol = imgSpr.getRGB(x,y);
if ((imgCol & 0xff000000) == 0)
continue;
if (!paint)
imgSpr.setRGB(x,y,imgCol&0xffffff); // set transparent
}
}
}
spr.img[frame] = imgSpr;
}
}
In short: I create an instance for each arrow object ("inFront") and remove each pixel (by making it transparent) that is not set in the underlying background stencil.