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

2015/3/18

How can I make a background out of 3 separate images?

decadence18 decadence18

2015/3/18

#
I want to paint the World (Background) with 3 separate images. These images do not need to be able to drag or anything, they simply need to make up the background. Is there any way of doing this?
danpost danpost

2015/3/19

#
The following constructor will draw three images onto the background image:
public Background()
{
    super (/** dimensions of world */); // create world
    GreenfootImage[] images =
    {
        new GreenfootImage("imageOne.jpg"), // adjust name of file as needed
        new GreenfootImage("imageTwo.jpg"), // adjust name of file as needed
        new GreenfootImage("imageThree.jpg") // adjust name of file as needed
    }; // create the images
    int x = 0; // starting x-coordinate for drawing images
    for (int n=0; n<images.length; n++) // for each image
    {
        getBackground().drawImage(images[n], x, 0); // draw image on background
        x += images[n].getWidth(); // set new x-coordinate for next image draw
    }
}
You need to login to post a reply.