J2ME Games apiの Build Maps Tiledlayer

Source: Internet
Author: User
Tags setcell

In J2me, the Game Wizard Sprite is a subclass of layer, and MIDP2.0 has an important class layer on the Tiledlayer layer interface, which is used to build game maps. In addition to the activities of the Elves in the game, but also need to have a background map, so that the wizard to walk around the map to form a realistic environmental effect, so MIDP2.0 provide us to build the game map of the Tiledlayer class, we can use Tiledlayer easy to build a beautiful image of a variety of map background. This paper describes an important method for Tiledlayer and if you use Tiledlayer to construct a game map.

1, Tiledlayer is a tiled tile in a lattice-lined cell, through the use of images to fill the whole station map of the cell to form a game map of the class.

2. The constructor of Tiledlayer is: public tiledlayer (int columns,int rows,image image,int-tiledwidth,int);

Where the parameter columns specifies the number of cell landscape and portrait in the layer, image specifies the image object that is used in the layer, and Tiledwidth and Tiledheight specify the dimensions of the image medium and small pictures respectively.

The image object, like the Sprite, is composed of several small pictures of different shapes, which can be seen from the construction method, and the Tiledlayer class can segment the image while constructing its own size.

Usage of Tiledlayer:

TiledLayer map;
    image = Image.create("/tl.png");
    map = new TiledLayer(9,9,image,image.getWidht()/9,image.getHeight());

3, Paste Brick

The process of assembling the segmented image into each cell in the map after building the map size with the split image is called tile. The method used is Setcell (int col,int row,int tiledindex), which is to paste the col picture on the map's tiledindex and row rows, and when all the cell is pasted, it forms the game map we want. In general, the cells in the map we use two-dimensional arrays to store the arrangement and to complete the tile task through a two-dimensional loop.

such as: Final static int[][] MapData = {

{4,4,4,4,4,4,4,4,4},
      {4,1,2,3,1,3,2,1,4},
      {4,1,5,1,1,2,4,3,4},
      {4,3,5,6,4,3,7,8,4},
      {4,3,6,7,7,7,3,2,4},
      {4,7,2,1,1,1,6,2,4},
      {4,3,6,7,7,7,3,2,4},
      {4,7,2,1,1,1,6,2,4},
      {4,4,4,4,4,4,4,4,4},
      };

Paste the Brick process:

for(int y = 0; y<mapData.length; y++){
       for(int x = 0; x<mapData[y].length; x++)
         {
            map.setCell(x,y,mapData[y][x]);
         }
      }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.