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

2011/7/18

Can't use setTransparency() or any GreenfootImage method. Please help

bobsingh40 bobsingh40

2011/7/18

#
Hi, I am trying to use setTransparency() method from one of my objects (Actor class object). I am calling this method from the act() method of the object. It gives me the following error: "non-static method setTransparency() cannot be referenced from a static context" In fact, I get this error if I use any of the methods in the GreenfootImage class. How do I get around this error so I can use these methods. Any help will be highly appreciated. Thanks, Bob
DonaldDuck DonaldDuck

2011/7/18

#
The methods in the GreenfootImage class have to be called after a reference to a GreenfootImage. To set the transparency of an image you need to have a image to affect,
getImage().setTransparency(255); // set the transparency of this actors image to fully visible

GreenfootImage image = new GreenfootImage("image name.png");
image.setTransparency(255); // set the transparency of a given image to fully visible

GreenfootImage canvas = new GreenfootImage(5,5);
canvas.setTransparency(canvas.getTransparency()-1); // set the transparency of a blank image to the current transparency of the image, minus one. You will get an error if it tries to set a transparency below 0.

Ant ant = (Ant) getOneIntersectingObject(Ant.class);
if(ant != null)
{
    ant.getImage().setTransparency(0); // set the transparency of another actors image to fully transparent (you must have direct reference to object for this)
}
bobsingh40 bobsingh40

2011/7/18

#
Thank you very very much. It fixed the problem. Really appreciate your help.
You need to login to post a reply.