title: LibGDX - Load a TiledMap tileset from a big TextureRegion
body: <p>I'm currently developing a game using LibGDX and I have come to the following situation:</p>
  
  <ol>
  <li>The game uses <code>TiledMap</code> maps for each level in it. I created a large tile set and packed it to a ~1300x1300 PNG file (non-POT). Tiles are 128x128 + gutter.</li>
  <li><p>The scene is rendered using an <code>OrthogonalTiledMapRenderer</code>. Actually it is a slight modification of the built-in <code>OrthogonalTiledMapRenderer</code>, which does not set the camera projection to the <code>SpriteBatch</code> renderer, causing an extra flush each loop:</p>
  
  <pre><code>private class OrthogonalTiledMapRenderer2 extends OrthogonalTiledMapRenderer {
      public OrthogonalTiledMapRenderer2 (TiledMap map, float unitScale, Batch batch) {
          super(map, unitScale, batch);
      }
  
      @Override
      public void setView (OrthographicCamera camera) {
          //batch.setProjectionMatrix(camera.combined); //This causes an unneeded flush in my case: the projection matrix is already set.
          float width = camera.viewportWidth * camera.zoom;
          float height = camera.viewportHeight * camera.zoom;
          viewBounds.set(camera.position.x - width / 2, camera.position.y - height / 2, width, height);
      }
  }
  </code></pre></li>
  <li><p>I draw several other objects (enemies, items, active elements) before I start rendering the tiledMap. This has to be this way since there are not tiles on all the cells of the map, and I want these objects to hide under some tiles. All this objects share the same camera projection, so I start the <code>SpriteBatch</code> when I want to render these objects, and leave it open when I start the map renderer. All these objects are currently packed into a texture about 1000x1000 in size, but it is comprised of lots of small objects so they can be wrapped around the tileset's region (read below). So the thing goes:</p>
  
  <pre><code>@Override
  public void render(float delta) {
      Gdx.gl.glClearColor(0, 0, 0, 1);
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  
      batch.setProjectionMatrix(camera.combined);
      batch.begin();
      for (Thing t : things) {
          t.draw(batch);
      }
      orthogonalTiledMapRenderer2.setView(camera);
      orthogonalTiledMapRenderer2.render(tileLayer); //Uses the same batch
      //...
       batch.end();
   }
  </code></pre></li>
  </ol>
  
  <p>Now, the thing is clear: My plan is to pack everything into a single Power-Of-Two texture (to the affordable size of 2048x2048), both the <code>TiledMap</code> tile set and the objects sheet, so I use a single texture and I can minimize batch flushes to the GPU. The problem is I can't find a way of loading a <code>TiledMap</code> using an external <code>SpriteRegion</code>, not even using the <code>AtlasTmxTiledMapLoader</code>.</p>
  
  <p>Can anyone point me in the right direction? Is there a way to load a <code>TiledMap</code> passing a <code>TextureRegion</code> as the tileset, instead of creating a new, unreachable <code>Texture</code>, and having to flush once for the map and again for the rest of your sprites?</p>