This java tip demonstrates how to use a Tiled Layer. The Layer is an abstract class that represents an element in the game. TiledLayer are inherited from Layer. Layer is mostly used by its subclasses. The TiledLayer is a little like Sprite but it is mainly meant for backgrounds, roads or other larger areas. TiledLayer consists of a grid of cells, which can be filled with images or tiles. So the background or scenery is built of small images.

 
 TiledLayer tiledLayer;
  Image bg;

  int tileData[][]={
   {11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
    11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
    11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
    11,11,11,11,11,11,11,11,11,11},
  
   {14,11,14,11,14,11,11,14,11,14,11,11,14,11,14,11,14,14,11,11,
    14,11,11,11,14,11,14,11,14,11,14,14,14,14,11,11,11,11,11,11,
    11,14,11,11,14,11,11,14,11,11,14,11,11,14,11,14,14,11,14,11,
    14,11,14,11,14,11,14,14,11,14},
  
   {13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,11,11,11,11,
    11,13,13,13,13,13,11,11,11,11,11,13,13,13,13,11,11,11,11,11,
    13,13,13,13,13,13,13,13,13,13,13, 9, 9, 9, 9, 9,11, 9,11, 9, 
    9, 9, 9, 9, 9, 9,11,11,11,11},

   {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,17,17,17,
    17,17,9,9,9,9,9,17,17,17,17,17,9,9,9,9,11,11,11,11,
    11,9,9,9,9,9,9,9,9,9,9,9,9,8,8,8,8,11,14,11, 
    8,8,9,9,8,8,8,9,11,11,11},

  {8,8,8,9,9,8,8,8,8,8,8,14,8,8,8,8,10,10,10, 
   10,10,8,8,14,8,8,10,10,10,10,10,8,8,8,8,10,9,10,9,10,
   8,8,14,8,8,8,8,14,8,8,8,8,8,8,8,8,10,8,10,9,9, 
   8,8,9,9,8,8,9,11,11 },

  {9,9,8,8,8,8,8,9,8,8,8,8,8,8,8,8,10,10,10, 
   10,10,8,8,8,8,8,10,10,10,10,10,8,8,8,8,10,10,10,10,10,
   8,8,9,9,9,9,9,9,8,8,8,8,8,8,8,8,10,8,10,8,8, 
   8,8,8,8,8,8,8,9,11 },
  
  {16,16,10,16,16,10,10,16,10,10,10,16,10,10,10,10,10,10,10,10,
   10,16,16,16,16,16,10,10,10,10,10,16,16,16,16,10,10,10,10,10,
   10,10,10,10,10,16,16,16,16,16,16,16,16,16,16,16,10,16,10,16,
   16,16,16,16,16,16,16,16,16,16},
  
  {10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
   10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
   10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
   10,10,10,10,10,10,10,10,10,10}
               
         };
  
  
  public initializeTiledLayer() {

    try{
      bg=Image.createImage("/bg.png");
    
    }catch(Exception e){}
  
    //Initialize the TIle Set
    tiledLayer=new TiledLayer(tileData[0].length,
      tileData.length, bg, 30, 30);
    
    //Set the tile data
    for(int i=0;i<set.length;i++)
    {
      for(int j=0;j<tileData[0].length;j++)
      {
        tiledLayer.setCell(j,i, set[i][j]) ;
      }
    }
    
  }
  
  //Paint the Tiled Layer  
  void paint(Graphics g)
  {
    tiledLayer.paint(g);
  }