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

2015/12/12

World Background

ironphoenix20 ironphoenix20

2015/12/12

#
Hi. I need help with setting an image from the internet as my world background. I tried importing file and using setBackground, but nothing works. Can someone help me?
danpost danpost

2015/12/12

#
Place the image file in the 'images' folder of your project folder. You can then set them image as the default image for any world object created from the class. Just right-click on the class and select 'Set image...' and then select the appropriate image for the class.
ironphoenix20 ironphoenix20

2015/12/13

#
I actually tried that already. It didn't work. Any other ideas?
ironphoenix20 ironphoenix20

2015/12/13

#
If I try your way, danpost, then I get an error that says "java.io.FileNotFoundException: C:\Users\EXAMPLE\Desktop\ICS3U\Final Project\Images\person.png (The system cannot find the file specified)"
ironphoenix20 ironphoenix20

2015/12/13

#
Actually, I got it to work, but the pictures too small so it's showing multiple copies of the picture for the background. So, I tried creating new image and setting width to 600 and height to 400 (size of world) and it opened paint. I uploaded my image into the paint file but its not saving. If I try to use that image as my background, it just shows white. What do I do? This is step 1 of my project, so can you help me ASAP?
danpost danpost

2015/12/13

#
In the constructor of the world, load the image, scale it to the world size and then set it as background. For example:
1
2
3
4
5
6
7
8
public MyWorld()
{
    super(600, 400, 1);
    GreenfootImage bg = new GreenfootImage("background.jpg");
    bg.scale(getWidth(), getHeight());
    setBackground(bg);
    // etc.
}
Do not use the full directory path when referencing an image file name in the 'images' folder.
ironphoenix20 ironphoenix20

2015/12/14

#
Thanks! That worked!
You need to login to post a reply.