I have a lighting system already working and (mostly) functional. I'm trying to implement translucency so that certain blocks (like water) only remove a fraction of light passing through them, and it works, but it stops working at the whole number limit of the lightmap (in my case, 20).
This is what it looks like:
and here is my code:
for(int x=0;x<mapX;x++){
for(int y=mapY-1;y>-1;y--){
try{
if(map[x][y] instanceof LightSource)
lightmap[x][y]=19;
else{
else{
if(x-1>-1&&lightmap[x][y]<lightmap[x-1][y])
lightmap[x][y]=lightmap[x-1][y]-map[x][y].translucency;
if(x+1<lv.map.length-1&&lightmap[x][y]<lightmap[x+1][y])
lightmap[x][y]=lightmap[x+1][y]-map[x][y].translucency;
if(y+1<lv.map[0].length-1&&lightmap[x][y]<lightmap[x][y+1])
lightmap[x][y]=lightmap[x][y+1]-map[x][y].translucency;
if(y-1>0&&lightmap[x][y]<lightmap[x][y-1])
lightmap[x][y]=lightmap[x][y-1]-map[x][y].translucency;
}
}
}catch(Exception e){}
}
}
Does anyone see what I'm doing wrong? Is there another system I could use to support transparency? Can anybody tell me at least why this is happening?
I fixed it by changing
for(int y=mapY-1;y>-1;y--)
to
for(int y=0;y<mapY-1;y++)
.
Absolutely no idea why that worked, though. Also, I'm afraid this same system might yield similar results if the light was coming from the bottom up instead of the top down. Haven't tested that yet, but it would make sense since all I did was change the order of the cellular automata.