title: LibGdx How to repeat background?
body: <p>Few days ago I figured out how to do some scrolling in LibGdx. Now I'm triying to do something related. I want to repeat the background. My scrolling follows a ship (Is an s[ace ship game). In the background there is a space photo loaded as a Texture. When the ship reach the end of the backgorund, It keeps going and there's no background anymore. I have read about wrap but I don't really understand How It works. I did that:</p>
  
  <pre><code>    px=new Pixmap(Gdx.files.internal("fondo.jpg"));
      background=new Texture(px);
      background.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
  </code></pre>
  
  <p>And then, in my render method</p>
  
  <pre><code>spriteBatch.begin();
      spriteBatch.draw(background,0,0,500,50);
      drawShip();
  spriteBatch.end();
  </code></pre>
  
  <p>Of course It doesn't work, It only draws the background once. I don't know how make this wrap method work. Any help?</p>
  
  <h1>SOLUTION</h1>
  
  <p>I figured It out. It's not a nice code but It works. </p>
  
  <p>First I declare two Textures with the same image</p>
  
  <pre><code> bck1=new Texture(Gdx.files.internal("fondo.jpg"));
   bck2=new Texture(Gdx.files.internal("fondo.jpg"));
  </code></pre>
  
  <p>Also I declare two variables like this to specify the X value of the position of each bck</p>
  
  <pre><code> int posXBck1=0,posXBck2=0;
  </code></pre>
  
  <p>Then I use that in Render()</p>
  
  <pre><code> public void calculoPosicionFondos(){
      posXBck2=posXBck1+ANCHODEFONDO;
      if(cam.position.x&gt;=posXBck2+cam.viewportWidth/2){
          posXBck1=posXBck2;
      }
  }
  </code></pre>
  
  <p>Where:</p>
  
  <p>ANCHODEFONDO is the width of my background</p>
  
  <p>Cam is an OtrhoCam.</p>
  
  <p>So I said that if the cam is in bck2 (wich means that you can't see bck1 anymore) It change positions, giving bck1 de position of bck2 and, in the next render loop, recalculating bck2</p>
  
  <p>Then just paint both bck in your render mode. </p>