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

2012/11/21

Setting a new background

Nerdbulwell Nerdbulwell

2012/11/21

#
Hi, I'm trying to make a game using Greenfoot, and I need to have the background change whenever I click on an arrow. I'm quite new to Greenfoot, and I need the simplest possible answer. I have the clicking arrow code in, but I do not know how to change the background. I need help, and I need it rather soon.
danpost danpost

2012/11/21

#
The World class has a 'setBackground(GreenfootImage)' method. The GreenfootImage class has several constructors you can use to create the image to set the background with. The easiest one to use is the GreenfootImage(String) constructor which accepts the name of an image file. So, in the Arrow class (if that is what you called it), use
getWorld().setBackground(new GreenfootImage("nameOfImageFile.png"));
Nerdbulwell Nerdbulwell

2012/11/23

#
Hi danpost, Thanks for the response, but I'm afraid it doesn't work. When I click the arrow, it comes up with a box which tells me it could not find the file. Any suggestions?
danpost danpost

2012/11/23

#
Did you import the image file into your scenario folder?
You need to login to post a reply.