Tabnine Logo
TiledMapTileSet
Code IndexAdd Tabnine to your IDE (free)

How to use
TiledMapTileSet
in
com.badlogic.gdx.maps.tiled

Best Java code snippets using com.badlogic.gdx.maps.tiled.TiledMapTileSet (Showing top 20 results out of 315)

origin: libgdx/libgdx

int firstgid = 1;
for (TiledMapTileSet tileset : tilesets) {
  firstgid += tileset.size();
TiledMapTileSet tileset = new TiledMapTileSet();
tileset.setName(id);
tileset.getProperties().put("firstgid", firstgid);
int gid = firstgid;
    TiledMapTile tile = new StaticTiledMapTile(new TextureRegion(texture, x, y, tileSizeX, tileSizeY));
    tile.setId(gid);
    tileset.putTile(gid++, tile);
  loadProperties(tileset.getProperties(), properties);
origin: libgdx/libgdx

/** @param id id of the {@link TiledMapTile} to get.
 * @return tile with matching id, null if it doesn't exist */
public TiledMapTile getTile (int id) {
  // The purpose of backward iteration here is to maintain backwards compatibility
  // with maps created with earlier versions of a shared tileset.  The assumption
  // is that the tilesets are in order of ascending firstgid, and by backward
  // iterating precedence for conflicts is given to later tilesets in the list, 
  // which are likely to be the earlier version of any given gid.  
  // See TiledMapModifiedExternalTilesetTest for example of this issue.
  for (int i = tilesets.size-1; i >= 0; i--) {
    TiledMapTileSet tileset = tilesets.get(i);
    TiledMapTile tile = tileset.getTile(id);
    if (tile != null) {
      return tile;
    }
  }
  return null;
}
origin: libgdx/libgdx

private String tilesetNameFromTileId (TiledMap map, int tileid) {
  String name = "";
  if (tileid == 0) {
    return "";
  }
  for (TiledMapTileSet tileset : map.getTileSets()) {
    int firstgid = tileset.getProperties().get("firstgid", -1, Integer.class);
    if (firstgid == -1) continue; // skip this tileset
    if (tileid >= firstgid) {
      name = tileset.getName();
    } else {
      return name;
    }
  }
  return name;
}
origin: libgdx/libgdx

TiledMapTileSet tileset = new TiledMapTileSet();
tileset.setName(name);
tileset.getProperties().put("firstgid", firstgid);
if (image != null) {
  TextureRegion texture = imageResolver.getImage(image.path());
  MapProperties props = tileset.getProperties();
  props.put("imagesource", imageSource);
  props.put("imagewidth", imageWidth);
      tile.setOffsetX(offsetX);
      tile.setOffsetY(flipY ? -offsetY : offsetY);
      tileset.putTile(id++, tile);
    tile.setOffsetX(offsetX);
    tile.setOffsetY(flipY ? -offsetY : offsetY);
    tileset.putTile(tile.getId(), tile);
  TiledMapTile tile = tileset.getTile(firstgid + localtid);
  if (tile != null) {
    Element animationElement = tileElement.getChildByName("animation");
      IntArray intervals = new IntArray();
      for (Element frameElement: animationElement.getChildrenByName("frame")) {
        staticTiles.add((StaticTiledMapTile) tileset.getTile(firstgid + frameElement.getIntAttribute("tileid")));
        intervals.add(frameElement.getIntAttribute("duration"));
  tileset.putTile(tile.getId(), tile);
origin: libgdx/libgdx

if (name.equals("TileSheet")) {
  currentTileSet = tilesets.getTileSet(currentChild.getAttribute("Ref"));
  firstgid = currentTileSet.getProperties().get("firstgid", Integer.class);
} else if (name.equals("Null")) {
  x += currentChild.getIntAttribute("Count");
} else if (name.equals("Static")) {
  Cell cell = new Cell();
  cell.setTile(currentTileSet.getTile(firstgid + currentChild.getIntAttribute("Index")));
  layer.setCell(x++, y, cell);
} else if (name.equals("Animated")) {
    if (frameName.equals("TileSheet")) {
      currentTileSet = tilesets.getTileSet(frame.getAttribute("Ref"));
      firstgid = currentTileSet.getProperties().get("firstgid", Integer.class);
    } else if (frameName.equals("Static")) {
      frameTiles.add((StaticTiledMapTile)currentTileSet.getTile(firstgid + frame.getIntAttribute("Index")));
origin: libgdx/libgdx

/** Constructs a Tile Set layout. The tile set image contained in the baseDir should be the original tile set images before
 * being processed by {@link TiledMapPacker} (the ones actually read by Tiled).
 * @param tileset the tile set to process
 * @param baseDir the directory in which the tile set image is stored */
protected TileSetLayout (int firstgid, TiledMapTileSet tileset, FileHandle baseDir) throws IOException {
  int tileWidth = tileset.getProperties().get("tilewidth", Integer.class);
  int tileHeight = tileset.getProperties().get("tileheight", Integer.class);
  int margin = tileset.getProperties().get("margin", Integer.class);
  int spacing = tileset.getProperties().get("spacing", Integer.class);
  this.firstgid = firstgid;
  image = ImageIO.read(baseDir.child(tileset.getProperties().get("imagesource", String.class)).read());
  imageTilePositions = new IntMap<Vector2>();
  // fill the tile regions
  int x, y, tile = 0;
  numRows = 0;
  numCols = 0;
  int stopWidth = image.getWidth() - tileWidth;
  int stopHeight = image.getHeight() - tileHeight;
  for (y = margin; y <= stopHeight; y += tileHeight + spacing) {
    for (x = margin; x <= stopWidth; x += tileWidth + spacing) {
      if (y == margin) numCols++;
      imageTilePositions.put(tile, new Vector2(x, y));
      tile++;
    }
    numRows++;
  }
  numTiles = numRows * numCols;
}
origin: libgdx/libgdx

/** @param name Name of the {@link TiledMapTileSet} to retrieve.
 * @return tileset with matching name, null if it doesn't exist */
public TiledMapTileSet getTileSet (String name) {
  for (TiledMapTileSet tileset : tilesets) {
    if (name.equals(tileset.getName())) {
      return tileset;
    }
  }
  return null;
}
origin: libgdx/libgdx

TiledMapTileSet tileset = new TiledMapTileSet();
MapProperties props = tileset.getProperties();
tileset.setName(name);
props.put("firstgid", firstgid);
props.put("imagesource", imageSource);
        tile.setOffsetX(offsetX);
        tile.setOffsetY(flipY ? -offsetY : offsetY);
        tileset.putTile(tileid, tile);
  TiledMapTile tile = tileset.getTile(tileid);
  if (tile == null) {
    Element imageElement = tileElement.getChildByName("image");
      tile.setOffsetX(offsetX);
      tile.setOffsetY(flipY ? -offsetY : offsetY);
      tileset.putTile(tileid, tile);
  TiledMapTile tile = tileset.getTile(firstgid + localtid);
  if (tile != null) {
    Element animationElement = tileElement.getChildByName("animation");
      IntArray intervals = new IntArray();
      for (Element frameElement: animationElement.getChildrenByName("frame")) {
        staticTiles.add((StaticTiledMapTile) tileset.getTile(firstgid + frameElement.getIntAttribute("tileid")));
        intervals.add(frameElement.getIntAttribute("duration"));
  tileset.putTile(tile.getId(), tile);
origin: libgdx/libgdx

if (name.equals("TileSheet")) {
  currentTileSet = tilesets.getTileSet(currentChild.getAttribute("Ref"));
  firstgid = currentTileSet.getProperties().get("firstgid", Integer.class);
} else if (name.equals("Null")) {
  x += currentChild.getIntAttribute("Count");
} else if (name.equals("Static")) {
  Cell cell = new Cell();
  cell.setTile(currentTileSet.getTile(firstgid + currentChild.getIntAttribute("Index")));
  layer.setCell(x++, y, cell);
} else if (name.equals("Animated")) {
    if (frameName.equals("TileSheet")) {
      currentTileSet = tilesets.getTileSet(frame.getAttribute("Ref"));
      firstgid = currentTileSet.getProperties().get("firstgid", Integer.class);
    } else if (frameName.equals("Static")) {
      frameTiles.add((StaticTiledMapTile)currentTileSet.getTile(firstgid + frame.getIntAttribute("Index")));
origin: libgdx/libgdx

/** Constructs a Tile Set layout. The tile set image contained in the baseDir should be the original tile set images before
 * being processed by {@link TiledMapPacker} (the ones actually read by Tiled).
 * @param tileset the tile set to process
 * @param baseDir the directory in which the tile set image is stored */
protected TileSetLayout (int firstgid, TiledMapTileSet tileset, FileHandle baseDir) throws IOException {
  int tileWidth = tileset.getProperties().get("tilewidth", Integer.class);
  int tileHeight = tileset.getProperties().get("tileheight", Integer.class);
  int margin = tileset.getProperties().get("margin", Integer.class);
  int spacing = tileset.getProperties().get("spacing", Integer.class);
  this.firstgid = firstgid;
  image = ImageIO.read(baseDir.child(tileset.getProperties().get("imagesource", String.class)).read());
  imageTilePositions = new IntMap<Vector2>();
  // fill the tile regions
  int x, y, tile = 0;
  numRows = 0;
  numCols = 0;
  int stopWidth = image.getWidth() - tileWidth;
  int stopHeight = image.getHeight() - tileHeight;
  for (y = margin; y <= stopHeight; y += tileHeight + spacing) {
    for (x = margin; x <= stopWidth; x += tileWidth + spacing) {
      if (y == margin) numCols++;
      imageTilePositions.put(tile, new Vector2(x, y));
      tile++;
    }
    numRows++;
  }
  numTiles = numRows * numCols;
}
origin: libgdx/libgdx

/** @param name Name of the {@link TiledMapTileSet} to retrieve.
 * @return tileset with matching name, null if it doesn't exist */
public TiledMapTileSet getTileSet (String name) {
  for (TiledMapTileSet tileset : tilesets) {
    if (name.equals(tileset.getName())) {
      return tileset;
    }
  }
  return null;
}
origin: libgdx/libgdx

TiledMapTileSet tileset = new TiledMapTileSet();
tileset.setName(name);
tileset.getProperties().put("firstgid", firstgid);
if (image != null) {
  TextureRegion texture = imageResolver.getImage(image.path());
  MapProperties props = tileset.getProperties();
  props.put("imagesource", imageSource);
  props.put("imagewidth", imageWidth);
      tile.setOffsetX(offsetX);
      tile.setOffsetY(flipY ? -offsetY : offsetY);
      tileset.putTile(id++, tile);
    tile.setOffsetX(offsetX);
    tile.setOffsetY(flipY ? -offsetY : offsetY);
    tileset.putTile(tile.getId(), tile);
  TiledMapTile tile = tileset.getTile(firstgid + localtid);
  if (tile != null) {
    Element animationElement = tileElement.getChildByName("animation");
      IntArray intervals = new IntArray();
      for (Element frameElement: animationElement.getChildrenByName("frame")) {
        staticTiles.add((StaticTiledMapTile) tileset.getTile(firstgid + frameElement.getIntAttribute("tileid")));
        intervals.add(frameElement.getIntAttribute("duration"));
  tileset.putTile(tile.getId(), tile);
origin: libgdx/libgdx

int firstgid = 1;
for (TiledMapTileSet tileset : tilesets) {
  firstgid += tileset.size();
TiledMapTileSet tileset = new TiledMapTileSet();
tileset.setName(id);
tileset.getProperties().put("firstgid", firstgid);
int gid = firstgid;
    TiledMapTile tile = new StaticTiledMapTile(new TextureRegion(texture, x, y, tileSizeX, tileSizeY));
    tile.setId(gid);
    tileset.putTile(gid++, tile);
  loadProperties(tileset.getProperties(), properties);
origin: libgdx/libgdx

private String tilesetNameFromTileId (TiledMap map, int tileid) {
  String name = "";
  if (tileid == 0) {
    return "";
  }
  for (TiledMapTileSet tileset : map.getTileSets()) {
    int firstgid = tileset.getProperties().get("firstgid", -1, Integer.class);
    if (firstgid == -1) continue; // skip this tileset
    if (tileid >= firstgid) {
      name = tileset.getName();
    } else {
      return name;
    }
  }
  return name;
}
origin: libgdx/libgdx

String tilesetCustomValue = tileset.getProperties().get(TILESET_PROPERTY_NAME, String.class);
if (!TILESET_PROPERTY_VALUE.equals(tilesetCustomValue)) {
  throw new RuntimeException("Failed to get tileset properties");
TiledMapTile tile = tileset.getTile(1);
String tileCustomValue = tile.getProperties().get(TILE_PROPERTY_NAME, String.class);
if (!TILE_PROPERTY_VALUE.equals(tileCustomValue)) {
origin: libgdx/libgdx

/** @param id id of the {@link TiledMapTile} to get.
 * @return tile with matching id, null if it doesn't exist */
public TiledMapTile getTile (int id) {
  // The purpose of backward iteration here is to maintain backwards compatibility
  // with maps created with earlier versions of a shared tileset.  The assumption
  // is that the tilesets are in order of ascending firstgid, and by backward
  // iterating precedence for conflicts is given to later tilesets in the list, 
  // which are likely to be the earlier version of any given gid.  
  // See TiledMapModifiedExternalTilesetTest for example of this issue.
  for (int i = tilesets.size-1; i >= 0; i--) {
    TiledMapTileSet tileset = tilesets.get(i);
    TiledMapTile tile = tileset.getTile(id);
    if (tile != null) {
      return tile;
    }
  }
  return null;
}
origin: com.badlogicgames.gdx/gdx-tools

/** Constructs a Tile Set layout. The tile set image contained in the baseDir should be the original tile set images before
 * being processed by {@link TiledMapPacker} (the ones actually read by Tiled).
 * @param tileset the tile set to process
 * @param baseDir the directory in which the tile set image is stored */
protected TileSetLayout (int firstgid, TiledMapTileSet tileset, FileHandle baseDir) throws IOException {
  int tileWidth = tileset.getProperties().get("tilewidth", Integer.class);
  int tileHeight = tileset.getProperties().get("tileheight", Integer.class);
  int margin = tileset.getProperties().get("margin", Integer.class);
  int spacing = tileset.getProperties().get("spacing", Integer.class);
  this.firstgid = firstgid;
  image = ImageIO.read(baseDir.child(tileset.getProperties().get("imagesource", String.class)).read());
  imageTilePositions = new IntMap<Vector2>();
  // fill the tile regions
  int x, y, tile = 0;
  numRows = 0;
  numCols = 0;
  int stopWidth = image.getWidth() - tileWidth;
  int stopHeight = image.getHeight() - tileHeight;
  for (y = margin; y <= stopHeight; y += tileHeight + spacing) {
    for (x = margin; x <= stopWidth; x += tileWidth + spacing) {
      if (y == margin) numCols++;
      imageTilePositions.put(tile, new Vector2(x, y));
      tile++;
    }
    numRows++;
  }
  numTiles = numRows * numCols;
}
origin: libgdx/libgdx

private void processSingleMap (File mapFile, FileHandle dirHandle, Settings texturePackerSettings) throws IOException {
  boolean combineTilesets = this.settings.combineTilesets;
  if (combineTilesets == false) {
    tilesetUsedIds = new HashMap<String, IntArray>();
    tilesetsToPack = new ObjectMap<String, TiledMapTileSet>();
  }
  map = mapLoader.load(mapFile.getCanonicalPath());
  // if enabled, build a list of used tileids for the tileset used by this map
  boolean stripUnusedTiles = this.settings.stripUnusedTiles;
  if (stripUnusedTiles) {
    stripUnusedTiles();
  } else {
    for (TiledMapTileSet tileset : map.getTileSets()) {
      String tilesetName = tileset.getName();
      if (!tilesetsToPack.containsKey(tilesetName)) {
        tilesetsToPack.put(tilesetName, tileset);
      }
    }
  }
  if (combineTilesets == false) {
    FileHandle tmpHandle = new FileHandle(mapFile.getName());
    this.settings.atlasOutputName = tmpHandle.nameWithoutExtension();
    packTilesets(dirHandle, texturePackerSettings);
  }
  FileHandle tmxFile = new FileHandle(mapFile.getCanonicalPath());
  writeUpdatedTMX(map, tmxFile);
}
origin: libgdx/libgdx

TiledMapTileSet tileset = new TiledMapTileSet();
MapProperties props = tileset.getProperties();
tileset.setName(name);
props.put("firstgid", firstgid);
props.put("imagesource", imageSource);
        tile.setOffsetX(offsetX);
        tile.setOffsetY(flipY ? -offsetY : offsetY);
        tileset.putTile(tileid, tile);
  TiledMapTile tile = tileset.getTile(tileid);
  if (tile == null) {
    Element imageElement = tileElement.getChildByName("image");
      tile.setOffsetX(offsetX);
      tile.setOffsetY(flipY ? -offsetY : offsetY);
      tileset.putTile(tileid, tile);
  TiledMapTile tile = tileset.getTile(firstgid + localtid);
  if (tile != null) {
    Element animationElement = tileElement.getChildByName("animation");
      IntArray intervals = new IntArray();
      for (Element frameElement: animationElement.getChildrenByName("frame")) {
        staticTiles.add((StaticTiledMapTile) tileset.getTile(firstgid + frameElement.getIntAttribute("tileid")));
        intervals.add(frameElement.getIntAttribute("duration"));
  tileset.putTile(tile.getId(), tile);
origin: com.badlogicgames.gdx/gdx

int firstgid = 1;
for (TiledMapTileSet tileset : tilesets) {
  firstgid += tileset.size();
TiledMapTileSet tileset = new TiledMapTileSet();
tileset.setName(id);
tileset.getProperties().put("firstgid", firstgid);
int gid = firstgid;
    TiledMapTile tile = new StaticTiledMapTile(new TextureRegion(texture, x, y, tileSizeX, tileSizeY));
    tile.setId(gid);
    tileset.putTile(gid++, tile);
  loadProperties(tileset.getProperties(), properties);
com.badlogic.gdx.maps.tiledTiledMapTileSet

Most used methods

  • getProperties
  • getTile
    Gets the TiledMapTile that has the given id.
  • getName
  • <init>
    Creates empty tileset
  • putTile
    Adds or replaces tile with that id
  • setName
  • size

Popular in Java

  • Creating JSON documents from java classes using gson
  • scheduleAtFixedRate (ScheduledExecutorService)
  • getExternalFilesDir (Context)
  • getResourceAsStream (ClassLoader)
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • Vector (java.util)
    Vector is an implementation of List, backed by an array and synchronized. All optional operations in
  • ZipFile (java.util.zip)
    This class provides random read access to a zip file. You pay more to read the zip file's central di
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now