Package tiled.core

Examples of tiled.core.Tile


  /* mostly copied from dialog/TilesetManager.java, except that
     many things refuse to compile with the usual tiled.jar,
     so rewrote it to work with more primitive interfaces. */
  private boolean isUsedTileset(final Map map, final TileSet tileset) {
    for (final Iterator< ? > tiles = tileset.iterator(); tiles.hasNext();) {
      final Tile tile = (Tile) tiles.next();

      for (final MapLayer layer : map) {
        if ((layer instanceof TileLayer) && (((TileLayer) layer).isUsed(tile))) {
          return true;
        }
View Full Code Here


   * @param tileset the tileset to be checked
   * @return true iff the tileset is in use
   */
  private boolean isUsedTileset(final Map map, final TileSet tileset) {
    for (final Iterator< ? > tiles = tileset.iterator(); tiles.hasNext();) {
      final Tile tile = (Tile) tiles.next();

      for (final MapLayer layer : map) {
        if ((layer instanceof TileLayer) && (((TileLayer) layer).isUsed(tile))) {
          return true;
        }
View Full Code Here

      return;
    }
    TileLayer tileLayer = (TileLayer) layer;
    for (int y = 0; y < tileLayer.getHeight(); y++) {
      for (int x = 0; x < tileLayer.getWidth(); x++) {
        Tile tile = tileLayer.getTileAt(x, y);
        if (tile != null) {
          tile = translateTile(tile);
          tileLayer.setTileAt(x, y, tile);
        }
      }
View Full Code Here

                        set.importTileBitmap(sourcePath, new BasicTileCutter(
                                tileWidth, tileHeight, tileSpacing, tileMargin));
                    }
                }
                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) {
            error = "Failed creating tile: " + e.getLocalizedMessage();
            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())) {
                Image img = unmarshalImage(child, baseDir);
                tile.setImage(img);
            } else if ("animation".equalsIgnoreCase(child.getNodeName())) {
                // TODO: fill this in once TMXMapWriter is complete
            }
        }
View Full Code Here

     * Helper method to get the tile based on its global id
     * @param tileId    global id of the tile
     * @return    <ul><li>{@link Tile} object corresponding to the global id, if found</li><li><code>null</code>, otherwise</li></ul>
     */
    private Tile getTileForTileGID(int tileId) {
        Tile tile = null;
        java.util.Map.Entry<Integer, TileSet> ts = findTileSetForTileGID(tileId);
        if (ts != null) {
            tile = ts.getValue().getTile(tileId - ts.getKey());
        }
        return tile;
View Full Code Here

        final int endY = Math.min(layer.getHeight(),
                (int) Math.ceil(clip.getMaxY() / tileHeight));

        for (int x = startX; x < endX; ++x) {
            for (int y = startY; y < endY; ++y) {
                final Tile tile = layer.getTileAt(x, y);
                if (tile == null)
                    continue;
                final Image image = tile.getImage();
                if (image == null)
                    continue;

                g.drawImage(
                        image,
View Full Code Here

            highlightColor = Color.decode(prefs.get("selectionColor", "#0000FF"));
        } catch (NumberFormatException e) {
            highlightColor = Color.blue;
        }

        selTile = new Tile();
        selection = new Area();
    }
View Full Code Here

        if (tileset != null && tileset.size() > 0) {
            listData = new Vector();
            Iterator tileIterator = tileset.iterator();

            while (tileIterator.hasNext()) {
                Tile tile = (Tile)tileIterator.next();
                listData.add(tile);
            }

            tileList.setListData(listData);
        }
View Full Code Here

                    Resources.getString("action.tile.delete.confirm.message"),
                    Resources.getString("action.tile.delete.confirm.title"),
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE);
            if (answer == JOptionPane.YES_OPTION) {
                Tile tile = (Tile)tileList.getSelectedValue();
                if (tile != null) {
                    tileset.removeTile(tile.getId());
                }
                queryTiles();
            }
        } else if (source == changeImageButton) {
            changeImage();
        } else if (source == addImagesButton) {
            addImages();
        } else if (source == duplicateTileButton) {
            Tile newTile = new Tile(currentTile);
            tileset.addNewTile(newTile);
            queryTiles();
            // Select the last (cloned) tile
            tileList.setSelectedIndex(tileset.size() - 1);
            tileList.ensureIndexIsVisible(tileset.size() - 1);
        } else if (source == editAnimationButton) {
          MapEditor.runTimer = false;
            AnimationDialog ad = new AnimationDialog(this, ((AnimatedTile)currentTile).getSprite());
            ad.setVisible(true);
            MapEditor.runTimer = true;
        }
        /*
        else if (source == setImagesCheck) {
            if (setImagesCheck.isSelected()) {
                tileset.enablesetImages();
                updateEnabledState();
            } else {
                int answer = JOptionPane.YES_OPTION;
                if (!tileset.safeToDisablesetImages()) {
                    answer = JOptionPane.showConfirmDialog(
                        this, "This tileset uses features that require the "
                        + "use of shared images.  Disable the use of shared "
                        + "images?",
                        "Are you sure?",
                        JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE);
                }
                if (answer == JOptionPane.YES_OPTION) {
                    tileset.disablesetImages();
                    updateEnabledState();
                } else {
                    setImagesCheck.setSelected(true);
                }
            }
        }
        */
        else if (source == createTileButton) {
          Image img = (Image) imageList.getSelectedValue();

            if (img != null) {
                Tile newTile = new Tile(tileset);

                newTile.setImage(tileset.getIdByImage(img));
                tileset.addNewTile(newTile);
                queryTiles();
                // Select the last (cloned) tile
                tileList.setSelectedIndex(tileset.size() - 1);
                tileList.ensureIndexIsVisible(tileset.size() - 1);
                JOptionPane.showMessageDialog(
                        this,
                        MessageFormat.format(
                                TILE_CREATED_MESSAGE,
                                new Object[]{new Integer(newTile.getId())}),
                        TILE_CREATED_TITLE,
                        JOptionPane.INFORMATION_MESSAGE);
            }
        }
        else if (source == createAnimatedTileButton) {
          Image img = (Image) imageList.getSelectedValue();

            if (img != null) {
                AnimatedTile newTile = new AnimatedTile(tileset);
                if(img.getWidth(null)%map.getTileWidth() != 0 || img.getHeight(null)%map.getTileHeight() != 0) {
                  JOptionPane.showMessageDialog(
                            this,
                            "The x and y sizes of the image aren't multiples of the tilewidth/height.",
                            "Couldn't create animated tile",
                            JOptionPane.ERROR_MESSAGE);
                  return;
                }
                int framesx = img.getWidth(null)/map.getTileWidth();
                int framesy = img.getHeight(null)/map.getTileHeight();
                Image frames[] = new Image[framesx*framesy];
               
                int id = tileset.addImage(img);
               
                for(int x = 0; x < framesx; x++) {
                  for(int y = 0; y < framesy; y++) {
                    frames[framesx*y+x] = createImage(new FilteredImageSource(img.getSource(), new CropImageFilter(x*map.getTileWidth(), y*map.getTileHeight(), map.getTileWidth(), map.getTileHeight())));
                  }
                }
               
                //TODO add delay input through dialog
                newTile.setSprite(new Sprite(frames, 10)); //chopped up animation
                newTile.setImage(id); //complete animation
                tileset.addNewTile(newTile);
                queryTiles();
                queryImages();
                // Select the last (cloned) tile
                tileList.setSelectedIndex(tileset.size() - 1);
                tileList.ensureIndexIsVisible(tileset.size() - 1);
                JOptionPane.showMessageDialog(
                        this,
                        MessageFormat.format(
                                TILE_CREATED_MESSAGE,
                                new Object[]{new Integer(newTile.getId())}),
                        TILE_CREATED_TITLE,
                        JOptionPane.INFORMATION_MESSAGE);
            }
        }

View Full Code Here

TOP

Related Classes of 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.