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

2013/3/31

Using getImage() in World classes

Phytrix Phytrix

2013/3/31

#
I was attempting to use a GreenfootImage command (getImage().*) in a World subclass earlier and it didn't recognise it. I believe my coding is appropriate. Can one not use GreenfootImage commands in World subclasses? If this is the case, why, and is there another way to do what I was trying to do (set the transparency of the background lower)? This was the code I was trying to use:
        GreenfootImage image = getImage();
        image.setTransparency(100);
danpost danpost

2013/3/31

#
It is not wise to add transparency to the world background. You will get some unwanted effects. However, as far as using 'getImage' in a subclass of World, 'getImage' is a method in the Actor class API, not the World class API. The method to get the GreenfootImage object of a world object in the World class API is the 'getBackground' method. There really is no need to change the background transparency as it is the backdrop image and nothing will show from behind it (except, like I said, some unwanted images). Try 'getBackground().clear();' (in your subclass of World) and then move the mouse around and see what happens. Not really what you wanted to see. What you could do, maybe, to get the effect you want, is to create an actor object whose image is as large as the world background and put the images you want on it and modify its transparencies.
Phytrix Phytrix

2013/3/31

#
I wanted it transparent so that there could be an underflow effect of an actor image (basically just waves, with the background on the World subclass as a still image of water). And what you said made sense. I suppose I didn't think about it not showing from behind... I'll do what you suggested and just use an Actor object and apply the transparency. Thanks for the explanation and the suggestion! :)
You need to login to post a reply.