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

2016/10/31

How would I gradually increase the size of an image?

Astralman Astralman

2016/10/31

#
Each object will increase in size by 5 (height and width). I'm working from the World class. For example, 1st object will be 5x5, 2nd object10x10, 3rd object 15x15, etc. I'm also trying to create a while loop.
1
2
3
4
5
6
7
8
9
10
private void setup ()
{
 
while (i < 25)
      {
       Cat cat = new Cat();
       addObject(cat, 100+15*i, 200);
       i++;
      }
}
I think the code to scale is:
1
2
3
GreenfootImage image = new GreenfootImage;
 image.scale(image.getWidth(), image.getHeight());
 setImage(image);
I don't know how to reference the cat class, though. I'm a beginner.
Super_Hippo Super_Hippo

2016/10/31

#
1
2
3
4
5
6
7
8
9
10
11
private void setup()
{
    for (int i=0; i<25; i++)
    {
        Cat cat = new Cat();
        addObject(cat, 100+15*i, 200);
        GreenfootImage image = cat.getImage();
        image.scale(image.getWidth()+i*5, image.getHeight()+i*5);
        cat.setImage(image);
    }
}
I think this should do this. But I guess that the last objects will be pretty huge and overlap each other.
danpost danpost

2016/10/31

#
Line 9 is not needed as the image is already set to the actor. Line 8 does not quite do what Astralman asked for, which is more like
1
image.scale((1+i)*5, (1+i)*5);
As far as overlapping, even with the change in scaling provided here (which would produce much smaller images to start with), by the time the counter gets to 3, they will start overlapping; and the last one created will hide all created before it from where the counter was 6 or 7.
Astralman Astralman

2016/11/2

#
Thanks guy :)
You need to login to post a reply.