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

2013/10/25

Make a resize powerup

winsticknova winsticknova

2013/10/25

#
Hi guys, so I'm trying to make it so if I step on an object I get a power-up where if you press "q" you shrink and if you press "w" you go back to your normal size. I can't figure out how to make it so my image doesn't become pixelated. After resizing it so many times the image becomes very distorted. help please!
danpost danpost

2013/10/25

#
Save the original image in a GreenfootImage field and when setting an alternate image create a new GreenfootImage with that saved image and scale or not.
winsticknova winsticknova

2013/10/25

#
i tried doing that but it doesn't seem to be working. can you tell me what's wrong with my code?
public void original()
    {
        if(Greenfoot.isKeyDown("w"))
        {
            GreenfootImage img = getImage();
            setImage(img);
        }
    }
    
    public void powerUp()
    {
        if(Greenfoot.isKeyDown("q"))
        {
            GreenfootImage image = getImage();
            image.scale(image.getWidth() - 2, image.getHeight() - 2);
            setImage(image);
        }
    }
danpost danpost

2013/10/25

#
The original image needs to be saved in an instance field. When necessary, that stored image can be used to create a NEW GreenfootImage object that can be scaled (do not rescale a image over and over again). You will also need a field to keep track of the size, so you can limit the size to between normal and some smaller number greater than zero (you will get an error trying to create an image with a size of zero or less.
winsticknova winsticknova

2013/10/25

#
thank you! i got it to work!
You need to login to post a reply.