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

2015/8/10

the transparency of another object

Milla Milla

2015/8/10

#
I am creating a game where an actor is going to touch an object that makes another object change from the transparency 100 to 255. In my class that is supposed to change the transparency of another class I've written this method: private void checkForGirl() { Girl girl = (Girl)getOneIntersectingObject(Girl.class); if (girl != null) { GreenfootImage image = new GreenfootImage("brick_blue.png"); image.setTransparency(255); } } This doesn't work, do I have to call for the Bluebrick class in some way?
danpost danpost

2015/8/10

#
Setting the transparency of a 'new' image is not the same as setting the transparency of an image already created and set to an actor. Please be aware that each actor has its own distinct image whether they are created from the same file or not and you will have to change the transparency of each one individually.
Milla Milla

2015/8/11

#
Ok thank you! Another question, how do i call a method from an actor subclass to a world subclass? I have an Actor called "Door" that have a method "hitDoor" that i want to call from my world subclass "Level". "hitDoor" is a boolean method that returns true if the "Girl" class have hit the door. In my Level class i want to write something like this: public void act() { if(((Door)getWorld.getObjects(Door.class).get(0)).hitDoor()) { nextMaze(); } } But this doesn't compile, how do i call the hitDoor method in a right way?
danpost danpost

2015/8/11

#
First, you are using 'getWorld' like it is a variable, not a method (there are no round brackets after it). Second, 'getWorld' is an Actor class method (not a World class method), meaning you need an actor to execute the method on. If the given act method is in the Level class, which is a subclass of World, it is already executing on a world object and you do not need to 'get' the world:
if (((Door)getObjects(Door.class).get(0)).hitDoor())
should work.
You need to login to post a reply.