Hi,
Thank you for the help and advice. I decided to split the tiles to an array first because it builds the environment from a 2D array of tile numbers, and I figured for building bigger environments it would be more efficient to call image from an array than copy specific pixels from a set with a bit of math for each tile.
I managed to duplicate the issue by adding something like what I'm doing to your code. I also added some lines to demonstrate the issue I'm having with copy.
Code:
PGraphics pgBack;
PGraphics pgBackEmpty;
PGraphics iconWithAlpha1;
PGraphics iconWithAlpha2;
PGraphics iconWithAlpha3;
void setup()
{
size(500, 500);
pgBack = createGraphics(200, 90, P2D);
pgBackEmpty = createGraphics(200, 90, P2D);
// Image with transparency
PImage piIcon = loadImage("icon.png");
//three PGraphics objects that will demonstrate the oddities I've observered in the PGraphics.copy method.
iconWithAlpha1 = createGraphics(piIcon.width, piIcon.height, P2D);
iconWithAlpha2 = createGraphics(piIcon.width, piIcon.height, P2D);
iconWithAlpha3 = createGraphics(piIcon.width, piIcon.height, P2D);
iconWithAlpha1.copy(piIcon, 0, 0, piIcon.width, piIcon.height, 0, 0, piIcon.width, piIcon.height);
//This will not copy the entire source-- instead, it will copy as though piIcon.width-1 and piIcon.height-1
//were specified as source dimensions, and thus, it will stretch them to fit the 1 pixel larger destination.
iconWithAlpha2.copy(piIcon, 0, 0, piIcon.width, piIcon.height, 0, 0, piIcon.width-1, piIcon.height-1);
//This will take the same parameters as above, but given the smaller destination, no scaling will occur
iconWithAlpha3.copy(piIcon, 0, 0, piIcon.width-1, piIcon.height-1, 0, 0, piIcon.width-1, piIcon.height-1);
//This will produce the same result as number 2, and will be true to the parameters entered.
//image(iconWithAlpha1, 0, 0);
//image(iconWithAlpha2, 0, 32);
//image(iconWithAlpha2, 0, 64);
pgBack.beginDraw();
pgBack.background(200);
pgBack.endDraw();
//Example of using copy to blit a PGraphics object with transparency to a PGraphics object already filled by background()
pgBack.image(iconWithAlpha1, 0, 0);
pgBack.image(iconWithAlpha2, 0, 32);
pgBack.image(iconWithAlpha3, 0, 64);
//Example of using copy to blit a PGraphics object with transparency to a PGraphics not yet filled by background()
pgBackEmpty.image(iconWithAlpha1, 0, 0);
pgBackEmpty.image(iconWithAlpha2, 0, 32);
pgBackEmpty.image(iconWithAlpha3, 0, 64);
}
void draw()
{
background(127);
//Blitting directly to screen
image(iconWithAlpha1, 0, 0);
image(iconWithAlpha2, 0, 32);
image(iconWithAlpha2, 0, 64);
//Transparency is preserved, but it would be too much to blit
//every tile every frame.
//Blitting from a PGraphics that's had background() run on it.
image(pgBack, 0, 96);
//Transparency is preserved between the iconWithAlphas and pgBack, but since the pixels on pgBack were already full and opaque,
//the transparency doesn't make it to the screen.
//Blitting from a PGraphics that did not have background run on it.
image(pgBackEmpty, 0, 192);
//Transparency is apparently discarded between the iconWithAlphas and pgBackEmpty, or the pixels that are transparent
//are simply not copied at all and the pixels on pgBackEmpty that were never set are defaulted to opaque #000000 in
//pgBackEmpty.
}
I put my comments on what I think is happening in the draw method, but they're just guesses, I'm not good enough to actually mess around in the Java end of things.
I don't think it is, but it could be the png I'm using. I last saved it from an older copy of Photoshop, so it should be up to standards, but I'm also on a Mac, and they love to mess around with images.