I think it will be easier to explain what I want to acomplish if I show my code fists$
I basicly want to be able to do theScalingWorld.scale(new width,new lenght); and that the world automaticly changes to the new size as wel as all the actors I might haven't come to the re-adding jet (i think I will have to calc the new Co-oords).
the problem is that It doesn't actually changes the size of the world only the backround image
feel free to use this buggy code!
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
/**
* Write a description of class ScalingWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class ScalingWorld extends World
{
static int oWidth;
static int oHeight;
static int currentWidth;
static int currentHeight;
static boolean first = true;
/**
* Constructor for objects of class ScalingWorld.
*
*/
public ScalingWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
if(first) {
first = false;
oWidth = getWidth();
oHeight = getHeight();
addObject(new Apple(),100,100); //for testing
}
}
public void scale(int newWidth,int newHeight) {
GreenfootImage background = getBackground();
background.scale(newWidth,newHeight);
List<Actor> actors = getObjects(null);
double xChange = newWidth/oWidth;
double yChange = newHeight/oHeight;
for(Actor a:actors) {
scaleActor(a,xChange,yChange);
}
ScalingWorld newWorld = new ScalingWorld();
newWorld.setBackground(background);
Greenfoot.setWorld(newWorld);
}
public void scaleActor(Actor actor, double xChange,double yChange) {
GreenfootImage image = actor.getImage();
int newX = (int) (image.getWidth()*xChange);
int newY = (int) (image.getHeight()*yChange);
if(newX <= 0) {
newX = 1;
}
if(newY <= 0) {
newY = 1;
}
image.scale(newX,newY);
actor.setImage(image);
}
public void scaleActor(Actor actor, int xPX,int yPX,boolean scaleInPixels) {
if(scaleInPixels) {
GreenfootImage image = actor.getImage();
image.scale(xPX,yPX);
actor.setImage(image);
}else {
scaleActor(actor,xPX,yPX);
}
}
}


