How to Rotate Images With Tile in Java

The "TiledLayer" class in Java creates images using tiles or a layered group of images. Each section of the image is a tile and each one contains a designated index value. You can rotate the images in the tiles using the Java loop function. The loop goes through each image and moves it to the next location.

Instructions

    • 1

      Open your preferred Java programming editor and the project you want to edit. Double-click the source code file to rotate the tiles.

    • 2

      Get the tiled image's grid data and determine the number of the column and row indexes. The following code retrieves the tiled image data:

      byte[][] tiles = getGridData();
      int rows = tiles.length;
      int columns = tiles[0].length;

    • 3

      Set up a new tiled layer used to rotate the images from the current tiled layout. The following code creates a new tiled layer:

      TiledLayer newtiles = new TiledLayer(columns, rows, tiles, TILE_WIDTH, TILE_HEIGHT);

    • 4

      Rotate the images. The following code uses the Java loop to move each image to the next location in the tiled layout:

      for(int y = 0; y < rows; y++) {
      for(int x = 0; x < columns; x++) {
      int tempindex= tiles[y+1][x+1];
      if(tileIndex > 0)
      newtiles.setCell(x, y, tempindex);
      }

    • 5

      Set the new layer as the image layout. The following code uses the new "newTiles" layer to assign the new layout:

      setTiledLayer(newTiles);

Related Searches:

References

Comments

Related Ads

Featured