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

2019/1/5

How to resize actor?

343qwm29 343qwm29

2019/1/5

#
I don't have any code yet because the whole idea falls apart if i can't resize an actor. I realize that I can just make a ton of different images and swap to larger ones, but my computer definitely cant handle that (it barely handles minecraft). So, is there some way to resize an actor or maybe change zoom out the background?
Super_Hippo Super_Hippo

2019/1/5

#
You can resize the image which is representing the actor in the world. Example: (changing the image to half its size)
1
2
3
4
5
6
public ClassName()
{
    GreenfootImage img = new GreenfootImage("pathToImage.png");
    img.scale(img.getWidth()/2, img.getHeight()/2);
    setImage(img);
}
343qwm29 343qwm29

2019/1/7

#
Well I'm trying to make the image grow slowly using act, and keeps recreating the image, growing it, then creating it again, so it grows when I run once, but it doesn't grow anymore. public void act() { GreenfootImage img = new GreenfootImage("pathToImage.png"); img.scale(img.getWidth()+10, img.getHeight()+10); setImage(img); } update: as I've tried more, I usually get one of 2 results. It either makes the image larger by making more or the same line of pixels, or it grows in a strange square pattern. I just want the image to get larger.
danpost danpost

2019/1/7

#
To have your width and height grow proportionally, you will need a factor field (or an offset to a factor value). Try this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
private GreenfootImage image;
private int sizer;
 
public ClassName()
{
    image = getImage();
}
 
private void grow()
{
    GreenfootImage img = new GreenfootImage(image);
    img.scale(img.getWidth()*(10+(++sizer))/10, img.getHeight()*(10+sizer)/10);
    setImage(img);
}
You need to login to post a reply.