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

2015/9/16

Help! How do I make a object larger?

4SeaBass 4SeaBass

2015/9/16

#
// I need the code to make a person image bigger. It is smaller than the other objects!
4SeaBass 4SeaBass

2015/9/16

#
And how do I make the screen or "camera" follow a certain player. Or certain object that you move around a large world.
danpost danpost

2015/9/16

#
You can use the 'scale' method on any GrenfootImage object to alter its size. You should only change the size of an image once after it is loaded or created to avoid unwanted effects to the image (unless you know what effects will occur and it happens to be what you are wanting). As an example:
1
2
3
4
GreenfootImage image = new GreenfootImage("<name of image file>");
int percent = 150; // for 50% larger image
image.scale(image.getWidth()*percent/100, image.getHeight()*percent/100);
setImage(image);
You can change the first line to:
1
GreenfootImage image = getImage();
and remove the last line as long as the code is placed in the constructor of the Actor subclass. For a "camera" follower system, you can download and use one of several scenarios with a scrolling support class and import that class into your project. I have one that is quite simple to use in my Bee Quick (ImgScroll Demo) scenario. It is for a world that is limited to some larger than the size of the visible part of the world. Usually, the size of the background image is used for limiting purposes. If the main player in your scenario is not limited to a certain area, then you can try using the scrolling engine in my Easy Infinite Scrolling Support Class scenario.
You need to login to post a reply.