java left logo
java middle logo
java right logo
 

Home arrow Java ME Tips
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4097
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to use a tiled layer in J2ME E-mail
User Rating: / 36
PoorBest 

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,1399999,119,119
    999999,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, 3030);
    
    //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);
  }


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.