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

2012/6/23

Wondering how to resize object/actor

1
2
ThinkingPainter ThinkingPainter

2012/6/23

#
I'm new to Greenfoot, wondering how to resize my actor for he is way to big would like him a bit smaller what would the code be for this? Thanks
SPower SPower

2012/6/23

#
In your constructor:
1
getImage.scale(..width.., ..height..);
ThinkingPainter ThinkingPainter

2012/6/23

#
getImage.scale(1); width(1); height(1); i put this in and its telling me "can not find symbol - variable getImage, how do i fix this i'm not understanding what you meaning when you tell me "in your constructor: getimage.scale(..width.., ..height);" how exactly should it look in my actor files? Thanks! ThinkingPainter
danpost danpost

2012/6/23

#
It should look like this
1
2
3
4
5
6
7
8
9
10
11
12
13
import greenfoot.*;
 
public class ClassName extends Actor
{
    public ClassName()
    {
        GreenfootImage image = getImage();
        image.scale(image.getWidth() - 10, image.getHeight() - 10);
        setImage(image);
    }
 
    //  rest of class
}
This will decrease the size of the image. I used '10' as the amount to decrease, though you may want to adjust the values to suit your needs, and they do not have to be the same amounts (i.e. you could decrease the width by 15 and the height by 20, or whatever).
ThinkingPainter ThinkingPainter

2012/6/23

#
Thanks for the code, have one problem.. "import greenfoot.*;" illegal start of type.. whats the correct way of fixing it thanks :)
danpost danpost

2012/6/23

#
What does your class look like?
ThinkingPainter ThinkingPainter

2012/6/23

#
import greenfoot.*; public class ClassName extends Actor { public ClassName() { GreenfootImage image = getImage(); image.scale(image.getWidth() - 10, image.getHeight() - 10); setImage(image); } // rest of class } is this what you mean?
danpost danpost

2012/6/23

#
Yes, and NO. What is the name of the class that you need to change the size of the image for?
ThinkingPainter ThinkingPainter

2012/6/23

#
oh, i named the image Blip
danpost danpost

2012/6/23

#
So, do you have a Blip class that extends Actor (a sub-class of Actor called 'Blip')?
ThinkingPainter ThinkingPainter

2012/6/23

#
Yes i think so i'm typing this code in the actors editor.
danpost danpost

2012/6/23

#
OK, change every occurance of the word 'ClassName' in the code I provided to 'Blip'. BTW, you should have, at least, these classes listed in the tan boxes between the 'Share' button in the top right corner and the 'Compile' button in the lower right corner of your scenario window: -World -<your sub-class of World> -Actor -Blip you may have others, but you should see at least these (in that order).
ThinkingPainter ThinkingPainter

2012/6/23

#
okay i changed the classname but "import greenfoot.*; " the first line of your code is still a illegal start of type }
danpost danpost

2012/6/23

#
When you create a sub-class, that line automatically inserted as the first line in the class code. There should not be any problems with it. Try removing the class and re-creating it. It should look something like this:
1
2
3
4
5
6
7
8
import greenfoot.*;
 
public class Blip extends Actor
{
    public void act()
    {
    }
}
You will also have some commenting, but that is basically it. Notice the 'import' line at the top (it is always there). All you need to do is add the constructor (just insert lines 5 through 10 of what I posted earlier at line 5 of the code in this post, using 'Blip', instead of 'ClassName'). It should not give an error.
ThinkingPainter ThinkingPainter

2012/6/24

#
All in pretty much working order, BUT, the actor "Blip" shrinks intill you can't see it and gives me this error: java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0 at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:999) at java.awt.GraphicsConfiguration.createCompatibleImage(GraphicsConfiguration.java:163) at greenfoot.util.GraphicsUtilities.createCompatibleTranslucentImage(GraphicsUtilities.java:179) at greenfoot.GreenfootImage.scale(GreenfootImage.java:403) at Blip.act(Blip.java:18) at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203) java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0 at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:999) at java.awt.GraphicsConfiguration.createCompatibleImage(GraphicsConfiguration.java:163) at greenfoot.util.GraphicsUtilities.createCompatibleTranslucentImage(GraphicsUtilities.java:179) at greenfoot.GreenfootImage.scale(GreenfootImage.java:403) at Blip.act(Blip.java:18) at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203)
There are more replies on the next page.
1
2