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

2011/12/4

GreenfootImage.setTransparency(int)

darkmist255 darkmist255

2011/12/4

#
I'm trying to give a fade-out effect for my "Shot" actor, and this is what I tried:
if(shotLife < 15)
        {
            GreenfootImage.setTransparency(240);
        }
        
        if(shotLife < 10)
        {
            GreenfootImage.setTransparency(170);
        }
        
        if(shotLife < 5)
        {
            GreenfootImage.setTransparency(140);
        }
        
        if(shotLife < 2)
        {
            GreenfootImage.setTransparency(40);
        }
But with this I get the "non-static method cannot be referenced from static context". Do I need to reference the image? I also tried it without the GreenfootImage. (so just setTransparency), but it didn't like that. How does one use the setTransparency command? Thanks for any help :D.
Builderboy2005 Builderboy2005

2011/12/4

#
If you want to set the transparency of the current Actor, use getImage() instead of GreenfootImage. By using GreenfootImage, Java believes you are trying to call setTransparency() as a static method in the class GreenfootImage, which is what is causing the problem :)
darkmist255 darkmist255

2011/12/5

#
Thanks :D!
You need to login to post a reply.