title: How to implement an infinite image loop?
body: <p>I am currently working on a 2D shooter with moving background. The background is just a simple image. I want to implement that the image is moving endless from top to bottom. </p>
  
  <p>I thought about determining the part of the image that is at the bottom outside the visible part of the frame and paint it on the top again. </p>
  
  <pre><code>@Override
  public void paint(Graphics go) {
      Graphics2D g = (Graphics2D) go;
  
      g.fillRect(0, 0, this.getWidth(), this.getHeight());
      g.drawImage(this.imgBackground, 0, this.yBackground, this);
  }
  </code></pre>
  
  <p>yBackground is the coordinate where the upper left corner of the image is drawn. It is altered from another thread:</p>
  
  <pre><code>while (!this.paused) {
      try {
          Thread.sleep(10);
      } catch (InterruptedException e) {
          e.printStackTrace();
      }
  
      int y = this.display.getBackgroundY();
  
      if (y == this.display.getHeight()) {
          y = 0;
      } else {
          y++;
      }
      this.display.setBackgroundY(y);
  }
  </code></pre>
  
  <p>So here is my question: how can I get the part of the image this is outside the visible part of the frame?</p>