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 :)


1 2 3 | Actor ground = new Ground(); addObject(ground, 0 , getHeight()-ground.getImage().getHeight()/ 2 ); addObject( new Ground(), ground.getImage().getWidth(), ground.getY()); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 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()); } } |
1 2 3 4 5 | for (Object obj : getObjects(Ground. class )) { Actor ground = (Actor)obj; // move ground } |