title: Libgdx Rendering Textures vs Sprites
body: <p>I am trying to build my first game with Libgdx and Box2d.
  The game has a similar concept as Flappy Bird. My issue is rendering the pipes.</p>
  
  <p>I have tried drawing rectangles and then drawing new sprite which I can size down to different pipe sizes every time the render method is called. the issue with doing so is that I cant dispose of the texture once the rectangle leaves the screen because it will make all the other rectangles that are still visible lose their texture. if I don't dispose of the texture once it leaves the screen it will make the game very slow after 20 seconds.</p>
  
  <p>The other option is to use about 10 different textures for different pipe sizes but still there is the issue of disposing of the textures.</p>
  
  <p>I would appreciate any suggestions how to efficiently render different pipe sizes. I have attached my render code below</p>
  
  <pre><code>  @Override
  public void render(float delta) {
      Gdx.gl.glClearColor(0,0,0,0);
      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
  
      world.step(BOX_STEP, BOX_VELOCITY_ITERATIONS, BOX_POSITION_ITERATIONS);
  
      batch.setProjectionMatrix(camera.combined);
  
      batch.begin();
      //background.setPosition(camera.position.x-camera.viewportWidth/2, camera.position.y-14);
      //background.draw(batch);
      batch.end();
  
      //bg1.update();
      //bg2.update();
  
      updateAnimation();
  
      if((TimeUtils.nanoTime()/10) - (lastDropTime/10) &gt; 300000000) 
          createPipes();
  
         batch.begin();
  
         for(Rectangle raindrop: raindrops) {
                pipe_top.setSize(4, raindrop.height);
            pipe_top.setPosition(raindrop.x,  raindrop.y);
            pipe_top.draw(batch);
  
            pipe_bottom.setSize(4, raindrop.height);
            pipe_bottom.setPosition(raindrop.x, camera.position.y + (camera.viewportHeight/2-pipe_bottom.getHeight()));
            pipe_bottom.draw(batch);
  
         }
         batch.end();
  
         if(pipe.getX() &lt; 0){
             pipe.getTexture().dispose();
         }
  
         Iterator&lt;Rectangle&gt; iter = raindrops.iterator();
            while(iter.hasNext()) {
               Rectangle raindrop = iter.next();
               raindrop.x -= 4 * Gdx.graphics.getDeltaTime();
  
               if(raindrop.x  &lt; -35) iter.remove();
  
            }
  
      debug.render(world, camera.combined);
  }
  </code></pre>