Due to the lack of information I have to guess how your algorithm, moving the tiles, work. But I suggest (as a working copy for the discussion) an algorithm I would come up with. The important thing is that I do move all tiles to the left in a separate loop. Otherwise if you move a Tile and if it is to far to the left remove it from the List and add it to the end of the List, you would process it twice. Is this possble the case in your code?
All tiles are sorted in the List from most left to most right. The algorithm keep them this way. The loops processes the most left one first to avoid overlapping (even so they are not drawn yet). As mentioned above, it is a guess due to the lack of information.
public interface Tile {
public void moveLeft(int pixel);
public void moveRight(int pixel);
public int getX();
}
public static void main(String[] args) {
int speedX = 20;
List<Tile> tiles = getMovingTiles();
for (Tile tile : tiles) tile.moveLeft(speedX);
while (tiles.get(0).getX() <= -60) {
Tile tile = tiles.remove(0);
tile.moveRight(840);
tiles.add(tile);
}
}
private static List<Tile> getMovingTiles() {
throw new UnsupportedOperationException("not yet implemented");
}
== UPDATE ==
A more efficient algorithm blueprint:
public interface Tile {
public void moveLeft(int pixel);
public int getX();
public void setX(int pixel);
}
public static void moveTiles(List<Tile> tiles, int speed, int offScreen, int startPos) {
tiles.add(null);
for (int idx = 0; tiles.get(idx) != null;) {
Tile tile = tiles.get(idx);
tile.moveLeft(speed);
if (tile.getX() <= offScreen) {
tile.setX(startPos);
tiles.add(tiles.remove(idx));
} else idx++;
}
tiles.remove(null);
}