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

2017/1/11

Resizing pictures

jacquelinereilly jacquelinereilly

2017/1/11

#
i want to make the picture smaller, it is in the world it is not an actor Thank you
jacquelinereilly jacquelinereilly

2017/1/11

#
import greenfoot.*;  

public class LevelScreen extends World
{
    public LevelOne ()
    {
        GreenfootImage image = getImage ();
        image.scale (image.getWidth () -300, image.getHeight ()-300);
        setImage (image);
    }
   
    public LevelScreen()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1); 
    }
}
danpost danpost

2017/1/11

#
jacquelinereilly wrote...
i want to make the picture smaller, it is in the world it is not an actor
First off, the 'getImage' and 'setImage' methods are in the Actor class -- not the World class. So, you cannot use them here. The getter/setter methods for the world background image are 'getBackground' and 'setBackground'. If you were to use 'getBackground' on your world that has a default image set to the class, it will not be the same exact image if the source was not the same size as that of the world -- it will either be tiled or cropped. You will need to get the image from the file and scale it to the world; then set it as the new background image of the world. For example:
GreenfootImage bg = new GreenfootImage("filename.jpg"); // adjust filename as needed
bg.scale(getWidth(), getHeight());
setBackground(bg);
danpost danpost

2017/1/11

#
Also, and I do not know if you copy/pasted funny or not--but, it appears you have two constructors in the same class with different class names -- namely 'LevelScreen' and 'LevelOne'. The compiler will have a fit over that. Insert my three lines after line 15 and remove lines 5 through 10.
jacquelinereilly jacquelinereilly

2017/1/12

#
it worked, thank you!!
You need to login to post a reply.