I've create a Scrolling engine which gets the coordinates of the player, and moves the player and the world so it scrolls. However, it doesn't seem to be moving anything but the player, and I have no Idea why. Could someone help me with this? Also, all of the terrain that the player interacts with (the collision physics are perfect, trust me) are subclasses of "Terrain", and do not have any coding.
import greenfoot.*; import java.util.List; public class XEngine extends World { public XEngine() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(600, 400, 1, false); addObject(new Base(250,"ImpossibleBlock.png"),getWidth()/2,getHeight()-50); addObject(new X(),getWidth()/2,getHeight()/2); addObject(new GridCoordinates(),getWidth()/2,40); } public void act(){ scrollingEngine(); fadeOverlayEngine(); } boolean autoScroll=true; int xX=0;//X's X coordinate int xY=0;//X's Y coordinate public void getCoordinates(int x, int y){xX=x; xY=y;} int xc=getWidth()/2;//X center of screen int yc=getHeight()/2;//Y center of screen int xcorrect=0;//How much world needs to be scrolled on the X-axis int ycorrect=0;//How much world need to be scrolled on the Y-axis int s=25;//How far from center X can stray before the screen scrolls public void scrollingEngine(){ xcorrect=0; ycorrect=0; if (autoScroll==true){ //Figure out how far away X is from the scrolling margin, if at all if (xX<xc-s){xcorrect=xc-s-xX;}else if (xX>xc+s){xcorrect=xc+s-xX;} if (xY<yc-s){ycorrect=yc-s-xY;}else if (xY>yc+s){ycorrect=yc+s-xY;} } //Scroll world, if at all ((GridCoordinates)getObjects(GridCoordinates.class).get(0)).giveGridCoordinates(xcorrect,ycorrect); if (xcorrect==0&&ycorrect==0)return; scroll(); } Class[] world = {Matter.class,Terrain.class,Shadow.class,Enemy.class,XExplosionGenerator.class,XBuster.class}; public void scroll(){ for (int i=0; i<world.length; i++){ List objects = getObjects(world[i]); if (! objects.isEmpty()){ for (int o=0; i<objects.size(); i++){ Actor object = (Actor) objects.get(o); object.setLocation(object.getX()+xcorrect,object.getY()+ycorrect); } } } } public void fadeOverlayEngine(){ } }