Is this something like what you want?


1 2 3 4 5 6 7 8 9 10 11 12 13 | 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 ; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | // 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(); } |