It seems that I need to use GreenfootImage#setColorAt(...) with a transparent Color(0,0,0,0) in order to remove / erase pixels, instead of GreenfootImage#drawRect(...) after setting the image color to transparent. This surprised me and seems counter intuitive. Can someone offer an explanation, please? Thanks in advance.
Details
I have a simple actor that is a transparent window that is placed over other actor locations. It can have a border drawn on it to draw focus to that location. Then the border can be reset or cleared.
and then
but this doesn't appear to work. Instead I had to use this approach:
I would have expected the drawRect method to eventually call the setColor method....?
Thanks.
public void drawBorder( Color c ) {
GreenfootImage img = getImage();
int width = img.getWidth();
int height = img.getHeight();
img.setColor( c );
for( int i=0; i<BORDER_WIDTH; i++ ) {
img.drawRect(i, i, width-(2*i+1), height-(2*i+1) );
}
} public void clearBorder() {
drawBorder( new Color( 0, 0, 0, 0 ) );
} public void erase() {
GreenfootImage img = getImage();
Color color = new Color( 0,0,0,0 );
img.setColor( color );
for( int r=0; r<img.getWidth(); r++ )
for(int c=0; c<img.getHeight(); c++ )
if( r < BORDER_WIDTH ||
r > img.getHeight() - BORDER_WIDTH - 1 ||
c < BORDER_WIDTH ||
c > img.getWidth() - BORDER_WIDTH - 1 )
img.setColorAt(r, c, color);
}

