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

2013/8/15

Changing background

mattjames mattjames

2013/8/15

#
Hi guys I'm still fairly new to greenfoot so need some basic help. Can someone please give me the code that will change the background when you press a button, for example "playbutton" and "modifybutton" being the two buttons that need to be pressed. I know that I could just send it to a different world class, however I would like to keep the entire game all in one world. Thanks
Gevater_Tod4711 Gevater_Tod4711

2013/8/15

#
The easyest way would be to set the backgroundimage of the world when the button is pressed:
//in your button;

public void act() {
    if (Greenfoot.mouseClicked(this)) {
        getWorld().setBackground(new GreenfootImage("imagePath.png"));
    }
}
mattjames mattjames

2013/8/15

#
Excellent thanks do I have to save the image in the 'images' folder by any chance??
Gevater_Tod4711 Gevater_Tod4711

2013/8/15

#
Yes all images you use have to be stored in the images folder in your project.
You need to login to post a reply.