Scratch for Java

TiledMap::getTileId()

Reads a global tile ID, without flip bits. Columns and rows are local to the named layer, starting at its top-left cell. Zero means an empty cell, including cells outside the layer. An unknown layer is an error.

Examples

 
import org.openpatch.scratch.Shape;
import org.openpatch.scratch.extensions.tiled.TiledMap;
 
/**
 * Reading map data does not need a window.
 * @example.online false
 */
public class TiledMapData {
  public TiledMapData() {
    TiledMap map = new TiledMap("src/examples/java/reference/assets/tiled-data.tmx");
    System.out.println(map.getProperty("biome", "forest"));
    System.out.println(map.getWidth() + " columns, " + map.getHeight() + " rows");
    System.out.println(map.getTileWidth() + " x " + map.getTileHeight() + " pixel cells");
    int tileId = map.getTileId("Ground", 1, 0);
    Shape[] localShapes = map.getTileCollisionShapes(tileId);
    Shape[] placedShapes = map.getTileCollisionShapes("Ground", 1, 0);
    for (Shape shape : placedShapes) System.out.println(shape.getBounds());
    // Use these shapes with the game's collision rules; rendering is optional.
  }
  public static void main(String[] args) { new TiledMapData(); }
}
 

View on GitHub

Syntax

Java

.getTileId(layerName, column, row)

Parameters

Name Data Type Description
layerName String tile layer name, also within a group
column int column index
row int row index

Return

int

getTileId()

Create Shareable URL

Select Sections