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: 3917
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:
 
 
 
Second method of using a tiled layer in mobile programming E-mail
User Rating: / 1
PoorBest 

This Java tip shows how to use tiled layers in mobile programming. 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.This can be used by game developers for developing tiled layers in their aplications.

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,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,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}
               
};

boolean toggle=false;

public init() {
    
    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]) ;
        }
    }
    
}

// Now paint the Tiled Layer
void paint(Graphics g) {
    tiledLayer.paint(g);
}

public void run() {
    while(true) {
        if(toggle)
            tiledLayer.setAnimatedTile(-17);
        else
            tiledLayer.setAnimatedTile(-110);
        toggle=toggle?false:true;
        
        repaint();
        try {
            Thread.sleep(100);
        }catch(Exception e){}
        
    }
}


 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.