SHARE
TWEET

Untitled

a guest Oct 6th, 2013 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.fortheloss.framework.tiled;
  2.  
  3. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  4. import com.badlogic.gdx.maps.MapObject;
  5. import com.badlogic.gdx.maps.tiled.TiledMap;
  6. import com.badlogic.gdx.maps.tiled.TiledMapTile;
  7. import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
  8. import com.badlogic.gdx.maps.tiled.renderers.BatchTiledMapRenderer;
  9.  
  10. public class OrthogonalTiledMapRenderer3 extends BatchTiledMapRenderer
  11. {
  12.    public OrthogonalTiledMapRenderer3(TiledMap map)
  13.    {
  14.       super(map);
  15.    }
  16.  
  17.    public OrthogonalTiledMapRenderer3(TiledMap map, SpriteBatch spriteBatch)
  18.    {
  19.       super(map, spriteBatch);
  20.    }
  21.    
  22.    public OrthogonalTiledMapRenderer3(TiledMap map, float unitScale)
  23.    {
  24.       super(map, unitScale);
  25.    }      
  26.    
  27.    public OrthogonalTiledMapRenderer3(TiledMap map, float unitScale, SpriteBatch spriteBatch)
  28.    {
  29.       super(map, unitScale, spriteBatch);
  30.    }
  31.    
  32.    @Override
  33.    public void renderObject(MapObject object)
  34.    {
  35.      
  36.    }
  37.  
  38.    @Override
  39.    public void renderTileLayer(TiledMapTileLayer layer)
  40.    {
  41.       final int layerWidth = layer.getWidth();
  42.       final int layerHeight = layer.getHeight();
  43.      
  44.       final float scaledTileWidth = layer.getTileWidth() * unitScale;
  45.       final float scaledTileHeight = layer.getTileHeight() * unitScale;
  46.      
  47.       final int col1 = Math.max(0, (int)(viewBounds.x / scaledTileWidth));
  48.       final int col2 = Math.min(layerWidth, (int)((viewBounds.x + viewBounds.width + scaledTileWidth) / scaledTileWidth));
  49.  
  50.       final int row1 = Math.max(0, (int)(viewBounds.y / scaledTileHeight));
  51.       final int row2 = Math.min(layerHeight, (int)((viewBounds.y + viewBounds.height + scaledTileHeight) / scaledTileHeight));            
  52.      
  53.       TiledMapTileLayer.Cell cell;
  54.       TiledMapTile tile;
  55.      
  56.       for (int row = row1; row < row2; ++row)
  57.       {
  58.          for (int col = col1; col < col2; ++col)
  59.          {
  60.             cell = layer.getCell(col, row);
  61.             if(cell == null)
  62.                continue;
  63.            
  64.             tile = cell.getTile();
  65.             if (tile == null)
  66.                continue;
  67.            
  68.             spriteBatch.draw(tile.getTextureRegion(), col * scaledTileWidth, row * scaledTileHeight, 0, 0, scaledTileWidth, scaledTileHeight, 1, 1, 0);
  69.          }
  70.       }
  71.    }
  72. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top