Is this something like what you want?
int trans = 0; while (y < sizeY / blockSize / .6) { y++; Dirt dirt = new Dirt(); GreenfootImage tint = new GreenfootImage(10, 10); tint.fill(); tint.setTransparency(trans); dirt.getImage().drawImage(tint, 0, 0); addObject(dirt, x, y); trans = trans+40; if (trans > 255) trans = 255; }
// in Block class // with instance fields int darkness, lightness, tint; GreenfootImage baseImg; // in Block constructor baseImg = getImage(); // the setLight method (renamed) private void updateImage() { if (Math.abs(tint-(darkness-lightness)) < 8) return; tint = darkness-lightness; GreenfootImage image = new GreenfootImage(baseImg); GreenfootImage tintImg = new GreenfootImage(image.getWidth(), image.getHeight()); tintImg.fill(); // default color for new image is black tintImg.setTransparency(tint); image.drawImage(tintImg, 0 ,0); setImage(image); } // with these methods public void setDarkness(int dark) { if (dark < 0) dark = 0; if (dark > 255) dark = 255; darkness = dark; updateImage(); } public void setLightness(int light) { if (light < 0) light = 0; if (light > 255) light = 255; lightness = light; updateImage(); }