Examples of TileSet


Examples of tiled.core.TileSet

            String filename = tilesetBaseDir + source;
            //if (checkRoot(source)) {
            //    filename = makeUrl(source);
            //}

            TileSet ext = null;

            try {
                InputStream in = new URL(makeUrl(filename)).openStream();
                ext = unmarshalTilesetFile(in, filename);
                setFirstGidForTileset(ext, firstGid);
            } catch (FileNotFoundException fnf) {
                error = "Could not find external tileset file " + filename;
            }

            if (ext == null) {
                error = "Tileset " + source + " was not loaded correctly!";
            }

            return ext;
        }
        else {
            final int tileWidth = getAttribute(t, "tilewidth", map != null ? map.getTileWidth() : 0);
            final int tileHeight = getAttribute(t, "tileheight", map != null ? map.getTileHeight() : 0);
            final int tileSpacing = getAttribute(t, "spacing", 0);
            final int tileMargin = getAttribute(t, "margin", 0);

            final String name = getAttributeValue(t, "name");

            TileSet set;
            if (settings.reuseCachedTilesets) {
                set = cachedTilesets.get(name);
                if (set != null) {
                    setFirstGidForTileset(set, firstGid);
                    return set;
                }
                set = new TileSet();
                cachedTilesets.put(name, set);
            } else {
                set = new TileSet();
            }

            set.setName(name);
            set.setBaseDir(basedir);
            setFirstGidForTileset(set, firstGid);

            boolean hasTilesetImage = false;
            NodeList children = t.getChildNodes();

            for (int i = 0; i < children.getLength(); i++) {
                Node child = children.item(i);

                if (child.getNodeName().equalsIgnoreCase("image")) {
                    if (hasTilesetImage) {
                        System.out.println("Ignoring illegal image element after tileset image.");
                        continue;
                    }

                    String imgSource = getAttributeValue(child, "source");
                    String transStr = getAttributeValue(child, "trans");

                    if (imgSource != null) {
                        // Not a shared image, but an entire set in one image
                        // file. There should be only one image element in this
                        // case.
                        hasTilesetImage = true;

                        // FIXME: importTileBitmap does not fully support URLs
                        String sourcePath = imgSource;
                        if (! new File(imgSource).isAbsolute()) {
                            sourcePath = tilesetBaseDir + imgSource;
                        }

                        if (transStr != null) {
                            if (transStr.startsWith("#"))
                                transStr = transStr.substring(1);

                            int colorInt = Integer.parseInt(transStr, 16);
                            Color color = new Color(colorInt);
                            set.setTransparentColor(color);
                        }

                        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

Examples of tiled.core.TileSet

        if (tilesets != null) {
            // Add a new tab for each tileset of the map
            for (Iterator it = tilesets.iterator(); it.hasNext();)
            {
                TileSet tileset = (TileSet) it.next();
                if (tileset != null) {
                    addTabForTileset(tileset);
                }
            }
        }
View Full Code Here

Examples of tiled.core.TileSet

    private Vector cells;

    public TileMergeHelper(Map map) {
        myMap = map;
        cells = new Vector();
        myTs = new TileSet();
        myTs.setName("Merged Set");
    }
View Full Code Here

Examples of tiled.core.TileSet

        OutputStream out = chunk.getOutputStream();
        String ver = map.getProperties().getProperty("version");
        if (ver == null || ver.length() < 3) {
            ver = "0.3";                            // default the value
        }
        TileSet set = (TileSet) map.getTilesets().get(0);

        //FIXME
        //out.write(Integer.parseInt(ver.substring(0,ver.indexOf('.')-1)));
        //out.write(Integer.parseInt(ver.substring(ver.indexOf('.')+1)));
        out.write(0);
        out.write(3);
        out.write(1); out.write(0);                 // LSB, reserved
        Util.writeShort(map.getWidth(), out);
        Util.writeShort(map.getHeight(), out);
        out.write(0); out.write(0); out.write(0); out.write(0);     // reserved
        Util.writeShort(map.getTileWidth(), out);
        Util.writeShort(map.getTileHeight(), out);
        Util.writeShort(16, out);                   // tile bitdepth
        Util.writeShort(32, out);                   // blkstr bytewidth
        Util.writeShort(findAllBlocks(map).size(), out);
        Util.writeShort(set.getMaxTileId(), out);

        chunks.add(chunk);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.