This site requires JavaScript, please enable it in your browser!
Greenfoot back
wabuilderman
wabuilderman wrote ...

2013/9/19

Help with dynamic grid lighting.

1
2
3
danpost danpost

2013/9/20

#
Is this something like what you want?
wabuilderman wabuilderman

2013/9/20

#
yes, but with it all fading to black. in other words: *above* + blackness, with *above* being the lightness of the given blocks.
danpost danpost

2013/9/20

#
So, you are saying that I have it fading the wrong way (toward white instead of what you want, toward black).
wabuilderman wabuilderman

2013/9/20

#
i guess.. i want what you have, just only in a way that it simply darkens the further form the top it is, rather than lightening stuff.
wabuilderman wabuilderman

2013/9/20

#
in other words: top block: full color second block: full block + a little black so forth and so forth till : full color + solid black
danpost danpost

2013/9/21

#
I came up with the following. It replaces the inside 'while' loop in your 'generateHills' method of your 'PlayerWorld' class.
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;
}
JetLennit JetLennit

2013/9/21

#
You could also try looking at this
JetLennit JetLennit

2013/9/21

#
You could also try looking at this Sorry, double post......
wabuilderman wabuilderman

2013/9/21

#
thanks danpost! only... can this be applied to a update cycle? and can this be used in sink with a 2nd light source?
wabuilderman wabuilderman

2013/9/21

#
i kind of understand your code, but i don't see how i can do a update...
danpost danpost

2013/9/21

#
It looks like you tried in your Block class to get the lighting system working. The main problem I see there, is you are saving the baseImg value from within a method instead of from within the constructor. If you use 'baseImg = getImage()' from within the constructor, then you can use 'GreenfootImage tempImg = new GreenfootImage(baseImg)' to get a copy of it in your setLight method. This way, you are not using an altered image to alter again. What I would probably do is add an int field to the class to hold the current tint (darkness minus lightness) and if the new values of darkness and lightness produce a value more than, let us say, 8 or 16 units away from the current value, then re-draw the image with the new tint and save that new tint value. All that has to be done then is updating the values of darkness and lightness.
wabuilderman wabuilderman

2013/9/21

#
umm... in english please?
danpost danpost

2013/9/21

#
How about in java:
// 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();
}
wabuilderman wabuilderman

2013/9/21

#
thx.
danpost danpost

2013/9/21

#
I noticed a bit of a problem with my last code-post. Will come up with a solution shortly.
There are more replies on the next page.
1
2
3