Package de.yaams.extensions.basemap.tiled.core

Examples of de.yaams.extensions.basemap.tiled.core.Tile


      zoomLabel.setText(String.valueOf((int) (mapView.getZoom() * 100)) + "%");

      // Get the first non-null tile from the first tileset containing
      // non-null tiles.
      Vector<TileSet> tilesets = currentMap.getTilesets();
      Tile firstTile = null;
      if (!tilesets.isEmpty()) {
        Iterator<TileSet> it = tilesets.iterator();
        while (it.hasNext() && firstTile == null) {
          firstTile = it.next().getFirstTile();
        }
View Full Code Here


    Polygon gridPoly;
    double gx;
    double gy;
    for (int y = startY; y <= endY; y++) {
      for (int x = startX; x <= endX; x++) {
        Tile t = layer.getTileAt(x, y);

        if (t != null) {
          if (layer.getClass() == SelectionLayer.class) {
            // TiledLogger.getLogger().info(
            // "selection tile at " + x + "," + y);
            gridPoly = createGridPolygon(x, y, 0);
            g2d.fillPolygon(gridPoly);
          } else {
            Point screenCoords = getTopLeftCornerOfTile(x, y);
            gx = screenCoords.getX();
            gy = screenCoords.getY();
            // TiledLogger.getLogger().info(
            // "image tile at " + x + "," + y
            // + " at " + gx + "," + gy);
            t.draw(g2d, (int) gx, (int) (gy + tsize.height), zoom);
          }
        }
      }
    }
  }
View Full Code Here

            String idValue = getAttributeValue(child, "id");
            int imageId = Integer.parseInt(idValue);
            set.addImage(image, imageId);
          }
        } else if (child.getNodeName().equalsIgnoreCase("tile")) {
          Tile tile = unmarshalTile(set, child, tilesetBaseDir);
          if (!hasTilesetImage || tile.getId() > set.getMaxTileId()) {
            set.addTile(tile);
          } else {
            Tile myTile = set.getTile(tile.getId());
            myTile.setProperties(tile.getProperties());
            // TODO: there is the possibility here of overlaying
            // images,
            // which some people may want
          }
        }
View Full Code Here

      }
    }
  }

  private Tile unmarshalTile(TileSet set, Node t, String baseDir) throws Exception {
    Tile tile = null;
    NodeList children = t.getChildNodes();
    boolean isAnimated = false;

    for (int i = 0; i < children.getLength(); i++) {
      Node child = children.item(i);
      if ("animation".equalsIgnoreCase(child.getNodeName())) {
        isAnimated = true;
        break;
      }
    }

    try {
      if (isAnimated) {
        tile = (Tile) unmarshalClass(AnimatedTile.class, t);
      } else {
        tile = (Tile) unmarshalClass(Tile.class, t);
      }
    } catch (Exception e) {
      Log.ger.error("failed creating tile: " + e.getLocalizedMessage());
      // e.printStackTrace();
      return tile;
    }

    tile.setTileSet(set);

    readProperties(children, tile.getProperties());

    for (int i = 0; i < children.getLength(); i++) {
      Node child = children.item(i);
      if ("image".equalsIgnoreCase(child.getNodeName())) {
        int id = getAttribute(child, "id", -1);
        Image img = unmarshalImage(child, baseDir);
        if (id < 0) {
          id = set.addImage(img);
        }
        tile.setImage(id);
      } else if ("animation".equalsIgnoreCase(child.getNodeName())) {
        // TODO: fill this in once XMLMapWriter is complete
      }
    }
View Full Code Here

   *            Number of Tiles to read
   * @throws IOException
   */
  private void readBGFXChunk(Map m, InputStream in, int num) throws IOException {
    TileSet set = m.getTilesets().get(0);
    set.addTile(new Tile());
    Util.readRawImage(in, twidth, theight); // skip the null-tile
    for (int i = 1; i < num; i++) {
      Tile t = new Tile();
      // t.setAppearance(image_id, 0);
      set.addTile(t);
    }
  }
View Full Code Here

    // Draw this map layer
    for (int y = 0; y < rows; y++) {
      Point columnItr = new Point(rowItr);

      for (int x = 0; x < columns; x++) {
        Tile tile = layer.getTileAt(columnItr.x, columnItr.y);

        if (tile != null) {
          if (layer instanceof SelectionLayer) {
            // Polygon gridPoly = createGridPolygon(
            // drawLoc.x, drawLoc.y - tileSize.height, 0);
            gridPoly.translate(drawLoc.x, drawLoc.y);
            g2d.fillPolygon(gridPoly);
            gridPoly.translate(-drawLoc.x, -drawLoc.y);
            // paintEdge(g2d, layer, drawLoc.x, drawLoc.y);
          } else {
            tile.draw(g2d, drawLoc.x, drawLoc.y, zoom);
          }
        }

        // Advance to the next tile
        columnItr.x++;
View Full Code Here

    public boolean equals(Cell c) {
      Iterator<Tile> me = sandwich.iterator();
      Iterator<Tile> them = c.sandwich.iterator();
      while (me.hasNext()) {
        Tile m = me.next();
        Tile t = them.next();
        if (m != null && t != null && !m.equals(t)) {
          return false;
        } else if (m != null && t != null && t != m) {
          return false;
        } else if ((m != null && t == null) || (m == null && t != null)) {
View Full Code Here

      // Write tile properties when necessary.
      Iterator<?> tileIterator = set.iterator();

      while (tileIterator.hasNext()) {
        Tile tile = (Tile) tileIterator.next();
        // todo: move the null check back into the iterator?
        if (tile != null && !tile.getProperties().isEmpty()) {
          startTable();
          writelnKeyAndValue("label", "tile");
          writelnKeyAndValue("id", tile.getId());
          writeProperties(tile.getProperties());
          endTable();
        }
      }
    } else {
      // Embedded tileset
View Full Code Here

          out = baos;
        }

        for (int y = 0; y < l.getHeight(); y++) {
          for (int x = 0; x < l.getWidth(); x++) {
            Tile tile = ((TileLayer) l).getTileAt(x + bounds.x, y + bounds.y);
            int gid = 0;

            if (tile != null) {
              gid = tile.getGid();
            }

            out.write(gid & LAST_BYTE);
            out.write(gid >> 8 & LAST_BYTE);
            out.write(gid >> 16 & LAST_BYTE);
            out.write(gid >> 24 & LAST_BYTE);
          }
        }

        if (compressLayerData) {
          ((GZIPOutputStream) out).finish();
        }

        writelnKeyAndValue("content", new String(Base64.encode(baos.toByteArray())));
      } else {
        for (int y = 0; y < l.getHeight(); y++) {
          for (int x = 0; x < l.getWidth(); x++) {
            Tile tile = ((TileLayer) l).getTileAt(x, y);
            int gid = 0;

            if (tile != null) {
              gid = tile.getGid();
            }

            startTable();
            writelnKeyAndValue("label", "tile");
            writelnKeyAndValue("gid", gid);
View Full Code Here

      for (int y = startY; y < endY; y++) {
        gx = 1;

        for (int x = 0; x < tilesPerRow && tileAt < tilesetMap.size(); x++, tileAt++) {
          Tile tile = tilesetMap.get(tileAt);

          if (tile != null) {
            tile.drawRaw(g, gx, gy + theight, 1.0);
          }
          gx += twidth;
        }
        gy += theight;
      }
View Full Code Here

TOP

Related Classes of de.yaams.extensions.basemap.tiled.core.Tile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.