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

2023/10/21

Help with cutting images

F4B10 F4B10

2023/10/21

#
Hi, the thing is that I made a class Platform, that in the constructor you can define the X and Y scales of the image, in order to have platforms with different shapes. The problem is that the image gets distorted because of the scaling. Can you give me an idea for making an overriden function scale(int x, int y) that instead of distortioning, cuts the image to that size?
danpost danpost

2023/10/22

#
F4B10 wrote...
I made a class Platform, that in the constructor you can define the X and Y scales of the image, in order to have platforms with different shapes. The problem is that the image gets distorted because of the scaling. Can you give me an idea for making an overriden function scale(int x, int y) that instead of distortioning, cuts the image to that size?
I am not sure why you are using the scale method. The following should be at least what you are looking for:
import greenfoot.*;

public class Platform extends Actor
{
    // constructor setting image of default size
    public Platform() {
        this(120, 16); // adjust default size as desired
    }
    
    // constructor setting image of given size
    public Platform(int width, int height) {
        GreenfootImage image = new GreenfootImage(width, height);
        image.fill();
        setImage(image);
    }
    
    // ... (rest of class code, if any)
}
You need to login to post a reply.