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

2013/1/8

Changing the background (world)

bbwf bbwf

2013/1/8

#
I have two backgrounds or worlds, one named lol and one named Space. How do I have the background change if a class is empty? This is what I have but it does not work to changing the background. if(getWorld().getObjects(Frog.class) == null || getWorld().getObjects(Frog.class).isEmpty()) { { getWorld().removeObject(this); setImage(new GreenfootImage("lol.jpg")); img.scale(850,550); setLocation(425, 275); // GreenfootImage img = getImage(); } Greenfoot.stop(); }
danpost danpost

2013/1/8

#
You do not have to do anything but start the new world from the old; and you definitely do not want to stop the scenario with 'Greenfoot.stop();'.
if(getWorld().getObjects(Frog.class) == null || getWorld().getObjects(Frog.class).isEmpty())
{
    Greenfoot.setWorld(new lol());
}
The new background, et al, should be coded in the 'lol' class.
Gevater_Tod4711 Gevater_Tod4711

2013/1/8

#
If you remove the object and then set it's image you can't see this and probably you get an exception. So what is it you want to change if there is no Frog object in your world. Also the part getWorld().getObjects(Frog.class) == null is not necessary because if ther is no frog this method will return a empty list but not null.
danpost danpost

2013/1/8

#
Yeah, I just copied the 'if' command from what was given and did not evaluate it. I was concerned mostly with getting the new world underway.
You need to login to post a reply.