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

2013/6/19

scaling an image

davemib123 davemib123

2013/6/19

#
I am trying to scale an image. This is what I have:
    private final GreenfootImage Midle= new GreenfootImage("mario-idle.gif");

    private boolean walking;
    private boolean facingRight;

    /**
     * An example of a method - replace this comment with your own
     */
    public Mario()
    {
        this.setImage(Midle);
        walking = false;
        facingRight = true;
    }
I've had a look at the API and it has a scale method. Question is how do I use it? I have tried:
private final GreenfootImage Midle= new GreenfootImage("mario-idle.gif");

Midle.scale(50,50);
but it just says identifier expected. Any ideas?
danpost danpost

2013/6/19

#
Watch your bracketing, or place the scaling call within a method (or constructor).
bourne bourne

2013/6/19

#
scale(int, int) is a method that resizes the GreenfootImage to the given size. Call it within the constructor, (by this simple use, I suggest scaling the image in an image editor to the desired size and saving - instead of using the scale method, unless you want variability in scale).
public Mario()  
{  
    Midle.scale(50, 50);
    setImage(Midle);  
    walking = false;  
    facingRight = true;  
} 
davemib123 davemib123

2013/6/20

#
Thanks guys. That's a great help. Question, how do you tell which of the methods in the API are to be applied within a constructor?
bourne bourne

2013/6/20

#
It can be placed within any method or constructor like all code. Typically you place it in the constructor if you want to do it only once (when the instance of the Object is created).
davmac davmac

2013/6/21

#
how do you tell which of the methods in the API are to be applied within a constructor?
All methods can only be called inside a constructor, method, initializer block, or (if they don't return void) as part of an assignment.
davemib123 davemib123

2013/6/21

#
davmac wrote...
how do you tell which of the methods in the API are to be applied within a constructor?
All methods can only be called inside a constructor, method, initializer block, or (if they don't return void) as part of an assignment.
Thanks davmac that is useful info :)
You need to login to post a reply.