/** * Creates a tileset from a buffered image. Tiles are cut by the passed cutter. * * @param tileBitmap the image to be used, must not be null * @param cutter the tile cutter, must not be null */ private void importTileBitmap(BufferedImage tileBitmap, TileCutter cutter) { assert tileBitmap != null; assert cutter != null; tileCutter = cutter; tileSetImage = tileBitmap; cutter.setImage(tileBitmap); tileDimensions = new Rectangle(cutter.getTileDimensions()); if (cutter instanceof BasicTileCutter) { BasicTileCutter basicTileCutter = (BasicTileCutter) cutter; tileSpacing = basicTileCutter.getTileSpacing(); tileMargin = basicTileCutter.getTileMargin(); tilesPerRow = basicTileCutter.getTilesPerRow(); } Image tileImage = cutter.getNextTile(); while (tileImage != null) { Tile tile = new Tile(); tile.setImage(tileImage); addNewTile(tile); tileImage = cutter.getNextTile(); } }
/** * Refreshes a tileset from a buffered image. Tiles are cut by the passed cutter. * * @param tileBitmap the image to be used, must not be null */ private void refreshImportedTileBitmap(BufferedImage tileBitmap) { assert tileBitmap != null; tileCutter.reset(); tileCutter.setImage(tileBitmap); tileSetImage = tileBitmap; tileDimensions = new Rectangle(tileCutter.getTileDimensions()); int id = 0; Image tileImage = tileCutter.getNextTile(); while (tileImage != null) { Tile tile = getTile(id); tile.setImage(tileImage); tileImage = tileCutter.getNextTile(); id++; } }