Can any one tell me how to make the ground move and then keep adding the same image behind it so its unlimited
if anyone can then thanks :)
Actor ground = new Ground(); addObject(ground, 0, getHeight()-ground.getImage().getHeight()/2); addObject(new Ground(), ground.getImage().getWidth(), ground.getY());
import greenfoot.*;
public class Ground extends Actor
{
private int unitWidth, imageWidth, worldWidth;
public void addedToWorld(World world)
{
worldWidth = world.getWidth();
GreenfootImage unit = getImage();
unitWidth = unit.getWidth();
imageWidth = (worldWidth/unitWidth+5)*unitWidth;
GreenfootImage image = new GreenfootImage(imageWidth, unit.getHeight());
for (int i=0; i<imageWidth; i+=unitWidth) image.drawImage(unit, i, 0);
setImage(image);
}
public void act()
{
if (getX() < -(imageWidth/2+unitWidth*3)) setLocation(getX()+2*imageWidth, getY());
if (getX() > worldWidth+(imageWidth/2+unitWidth*3)) setLocation(getX()-2*imageWidth, getY());
}
}for (Object obj : getObjects(Ground.class))
{
Actor ground = (Actor)obj;
// move ground
}