Guest User

Untitled

a guest
Dec 20th, 2011
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1.     public class MyAtlas extends TileAtlas {
  2.        
  3.  
  4.         public MyAtlas(TiledMap map) {
  5.            
  6.             for (TileSet set : map.tileSets) {
  7.  
  8.  
  9.                 Texture text = new Texture(dir + "/" + set.imageName);
  10.                
  11.                 int textureWidth = text.getWidth();
  12.                 int textureHeight = text.getHeight();
  13.                
  14.                 AtlasRegion reg;                
  15.  
  16.                 int index = 0;                
  17.                 for(int y = 0 ; y < textureHeight / set.tileHeight ; y++) {
  18.                     for(int x = 0 ; x < textureWidth / set.tileHeight ; x++) {
  19.                         if(x * set.tileWidth + (x * set.spacing) + set.tileWidth > text.getWidth()) continue;
  20.                         reg = new AtlasRegion(text, x * set.tileWidth + (x * set.spacing), y * set.tileHeight + (y*set.spacing), set.tileWidth, set.tileHeight);                       
  21.                         regionsMap.put(index + set.firstgid, reg);
  22.                         index++;
  23.                     }
  24.                 }
  25.                
  26.  
  27.             }
  28.         }      
  29.  
  30.         public TextureRegion getRegion(int id) {
  31.             return regionsMap.get(id);
  32.         }
  33.     }
Advertisement
Add Comment
Please, Sign In to add comment