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

2019/3/3

Change World Image from inside the Actor

xandreas_1 xandreas_1

2019/3/3

#
I want to change my World Backgrund from inside an Actor: This is what I got so far:
GameOver world = (GameOver) getWorld();
            world.setImage("GameOver2.png");
it says: cannot find symbol - method setImage(java.lang.String) Is there a mistake inside the brackets behind setImage? Thx already
danpost danpost

2019/3/3

#
xandreas_1 wrote...
I want to change my World Backgrund from inside an Actor: This is what I got so far: << Code Omitted >> it says: cannot find symbol - method setImage(java.lang.String) Is there a mistake inside the brackets behind setImage? Thx already
No. There is a mistake as to what methods are available for your subclasses of World. Refer to the API documentation of World to find out what methods are available.
xandreas_1 xandreas_1

2019/3/3

#
danpost wrote...
xandreas_1 wrote...
I want to change my World Backgrund from inside an Actor: This is what I got so far: << Code Omitted >> it says: cannot find symbol - method setImage(java.lang.String) Is there a mistake inside the brackets behind setImage? Thx already
No. There is a mistake as to what methods are available for your subclasses of World. Refer to the API documentation of World to find out what methods are available.
I tried setBackground but it also does#t work
danpost danpost

2019/3/3

#
xandreas_1 wrote...
I tried setBackground but it also does#t work
What is the error message now?
xandreas_1 xandreas_1

2019/3/3

#
danpost wrote...
xandreas_1 wrote...
I tried setBackground but it also does#t work
What is the error message now?
java.lang.ClassCastException: Welt cannot be cast to GameOver
danpost danpost

2019/3/3

#
xandreas_1 wrote...
java.lang.ClassCastException: Welt cannot be cast to GameOver
Apparently, the code is being executed while your Welt world is active -- not a GameOver world. Show the entire method which contains those lines.
xandreas_1 xandreas_1

2019/3/3

#
public void GameStop() { GreenfootSound sound2 = ((Welt)getWorld()).sound2; if(Tankfüllung == -1) { sound2.stop(); car.sound1.stop(); GameOver world = (GameOver) getWorld(); world.setBackground("GameOver2.png"); this.Tankfüllung = 50; if(Timer == 10) {Greenfoot.setWorld(new GameOver()); } else { Timer++; } } }
danpost danpost

2019/3/3

#
You need to create your GameOver world before you can set its background.
xandreas_1 xandreas_1

2019/3/3

#
ah yes thx
You need to login to post a reply.