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

2018/2/27

Scaling Images

Agent40 Agent40

2018/2/27

#
Hi, I was wondering if there was a better way to scale images in Greenfoot that isn't based on a Variable created around the image i.e.
1
2
3
GreenfootImage image = getImage(); 
        image.scale(30, 30);
        setImage(image);
(Right now I'm using an Array to load these images and animate Actors so I hope you can see why using the code above would be a pain) Thanks in Advance. Extra Question: Is there a way to scale the size of Greenfoot as a whole seeing as it has terrible size management and only allows you to build a program based around pixels and not a whole texture?
danpost danpost

2018/2/27

#
To answer the Extra question first -- greenfoot has you specify a cell size; 1 for pixel-size cells and larger values for larger cells. It is in the 'super' call in your world constructor. You can increase the third value (the '1') to create larger cells. The other two values, for world width and height, will have to be lowered to keep the world at a reasonable size. Try something like 'super(6, 4, 100);'. Have an actor with any standard actor image follow the mouse. Start the scenario and move the mouse around the screen and see how the actor moves. Instead of the example code above, you should probably show your actual code. That way you might get some advice on how to improve it.
Agent40 Agent40

2018/2/27

#
I've tried working with the cell size before but have had no luck in the past. I guess I'll go back and give it another shot though. Could you give me an estimate of how big X =454 and Y =781 would be? On the topic of the code, This is the code that I'm using to load the images:
1
2
3
4
5
6
7
8
9
LengthOfAnimation[0][0] = 8;
        Image[0][0][0] = new GreenfootImage("Fina_Idle_1.png");
        Image[0][0][1] = new GreenfootImage("Fina_Idle_2.png");
        Image[0][0][2] = new GreenfootImage("Fina_Idle_3.png");
        Image[0][0][3] = new GreenfootImage("Fina_Idle_4.png");
        Image[0][0][4] = new GreenfootImage("Fina_Idle_5.png");
        Image[0][0][5] = new GreenfootImage("Fina_Idle_6.png");
        Image[0][0][6] = new GreenfootImage("Fina_Idle_7.png");
        Image[0][0][7] = new GreenfootImage("Fina_Idle_8.png");
It uses a Third Dimensional array to Animate and load each image for the class. I have about 20 of these Sets on each Actor. The only problem with them is that each image is Pixel art and if I manually edit them with Photoshop, paint.net, etc. They all break due to the fact that 1.5x the size for pixel art doesn't work.
danpost danpost

2018/2/28

#
Agent40 wrote...
Could you give me an estimate of how big X =454 and Y =781 would be?
The '781' is a bit large for the y-dimension. I try never to go past '600' in that direction as mos monitors just are not that big vertically.
Agent40 Agent40

2018/2/28

#
danpost wrote...
Agent40 wrote...
Could you give me an estimate of how big X =454 and Y =781 would be?
The '781' is a bit large for the y-dimension. I try never to go past '600' in that direction as mos monitors just are not that big vertically.
It fits fine for all 1080p Monitors I've used and that should be standard. Any suggestions for Scaling the images loading through the array though?
danpost danpost

2018/2/28

#
Try in constructor:
1
2
3
4
5
6
7
for (int i=0; i<LengthOfAnimation[0][0].length; i++)
{
    GreenfootImage img = LengthOfAnimation[0][0][i];
    int w = img.getWidth();
    int h = img.getHeight();
    img.scale(w*3/2, h*3/2);
}
Agent40 Agent40

2018/2/28

#
Ok, I've looked at this code and I'm trying to understand it. So when this runs, would this check for each image within the set then adjust that each image every time it updates? or would I have to manually do that for each?
1
Image[Character][Set][Stage]
danpost danpost

2018/2/28

#
Agent40 wrote...
when this runs, would this check for each image within the set then adjust that each image every time it updates? or would I have to manually do that for each?
The code given does all 8 of what you had in the code you gave. You can use outer loops to do the entire set of images in the array. Almost never do you want to scale an image more than once. Scaling an image multiple times will cause unwanted results in general.
Agent40 wrote...
when this runs, would this check for each image within the set then adjust that each image every time it updates? or would I have to manually do that for each?
You do not have to do anything manually -- just implement the code. It will, if placed correctly in your code, adjust all images in the array to 150% their original size.
Agent40 Agent40

2018/2/28

#
danpost wrote...
Agent40 wrote...
when this runs, would this check for each image within the set then adjust that each image every time it updates? or would I have to manually do that for each?
The code given does all 8 of what you had in the code you gave. You can use outer loops to do the entire set of images in the array. Almost never do you want to scale an image more than once. Scaling an image multiple times will cause unwanted results in general.
Agent40 wrote...
when this runs, would this check for each image within the set then adjust that each image every time it updates? or would I have to manually do that for each?
You do not have to do anything manually -- just implement the code. It will, if placed correctly in your code, adjust all images in the array to 150% their original size.
Thanks, for the Help. Will give this a try now.
Agent40 Agent40

2018/3/5

#
Ok, I came across 2 problems when I attempted to use this code. The first came from i<LengthofAnimation.length (red underline for .length). the error says "int cannot be dereferenced". The second comes from GreenfootImage img = LengthOfAnimation; (red underline for ) and it says "array required, but int found"
danpost danpost

2018/3/6

#
Sorry, 'LengthOfAnimation' was supposed to be 'Image' in both lines 1 and 3.
You need to login to post a reply.