use of com.b3dgs.lionengine.graphic.drawable.SpriteTiled in project lionengine by b3dgs.
the class TilesExtractor method extract.
/**
* Start using specified output file. Listeners are cleared once ended.
*
* @param canceler The canceler reference (can be <code>null</code>).
* @param tw The tile width.
* @param th The tile height.
* @param levelRips The levels rip used.
* @return The extracted tile sheets.
* @throws LionEngineException If an error occurred when computing sheet.
*/
public Collection<ImageBuffer> extract(Canceler canceler, int tw, int th, Collection<Media> levelRips) {
final int tilesNumber = getTilesNumber(tw, th, levelRips);
final Collection<ImageBuffer> tiles = new ArrayList<>();
int checkedTiles = 0;
for (final Media levelRip : levelRips) {
final SpriteTiled level = Drawable.loadSpriteTiled(levelRip, tw, th);
level.load();
level.prepare();
checkedTiles = extract(canceler, level, tilesNumber, tiles, checkedTiles);
level.getSurface().dispose();
if (checkedTiles < 0) {
break;
}
}
listeners.clear();
return tiles;
}
use of com.b3dgs.lionengine.graphic.drawable.SpriteTiled in project lionengine by b3dgs.
the class MapTileViewerModel method renderTile.
/*
* MapTileRenderer
*/
@Override
public void renderTile(Graphic g, Tile tile, int x, int y) {
final SpriteTiled sprite = map.getSheet(tile.getSheet());
sprite.setLocation(x, y);
sprite.setTile(tile.getNumber());
sprite.render(g);
}
use of com.b3dgs.lionengine.graphic.drawable.SpriteTiled in project lionengine by b3dgs.
the class UtilMapTilePersister method createMap.
/**
* Create a test map.
*
* @return The created test map.
*/
public static MapTile createMap() {
final MapTileGame map = new MapTileGame();
map.addFeature(new MapTilePersisterModel());
map.create(16, 32, 3, 3);
map.loadSheets(new ArrayList<SpriteTiled>());
for (int tx = 0; tx < map.getInTileWidth(); tx++) {
for (int ty = 1; ty < map.getInTileHeight(); ty++) {
map.setTile(tx, ty, tx * ty);
}
}
return map;
}
use of com.b3dgs.lionengine.graphic.drawable.SpriteTiled in project lionengine by b3dgs.
the class Minimap method computeSheet.
/**
* Compute the current sheet.
*
* @param colors The colors data.
* @param sheetId The sheet id.
*/
private void computeSheet(Map<Integer, ColorRgba> colors, int sheetId) {
final SpriteTiled tiles = map.getSheet(sheetId);
final ImageBuffer tilesSurface = tiles.getSurface();
final int tw = map.getTileWidth();
final int th = map.getTileHeight();
int number = 0;
for (int i = 0; i < tilesSurface.getWidth(); i += tw) {
for (int j = 0; j < tilesSurface.getHeight(); j += th) {
final int h = number * tw % tiles.getWidth();
final int v = number / tiles.getTilesHorizontal() * th;
final ColorRgba color = UtilColor.getWeightedColor(tilesSurface, h, v, tw, th);
if (!(NO_TILE.equals(color) || color.getAlpha() == 0)) {
colors.put(Integer.valueOf(number), color);
}
number++;
}
}
}
use of com.b3dgs.lionengine.graphic.drawable.SpriteTiled in project lionengine by b3dgs.
the class SheetsExtractor method extract.
/**
* Convert a set of tile to a set of tile sheets.
*
* @param tiles The list of tiles.
* @param horizontalTiles The number of horizontal tiles on sheet (inferior or equal to 0 to use automatic).
* @return The list of tile sheets.
*/
public static List<SpriteTiled> extract(Collection<ImageBuffer> tiles, int horizontalTiles) {
final Surface surface = getSheetSize(tiles, horizontalTiles);
final int horizontals = surface.getWidth();
final int verticals = surface.getHeight();
final int tilesPerSheet = Math.min(tiles.size(), horizontals * verticals);
final List<SpriteTiled> sheets = new ArrayList<>();
ImageBuffer sheet = null;
Graphic g = null;
int number = 0;
int tw = 0;
int th = 0;
for (final ImageBuffer tile : tiles) {
if (g == null) {
tw = tile.getWidth();
th = tile.getHeight();
final int width = Math.max(tw, horizontals * tw);
final int height = Math.max(th, verticals * th);
sheet = Graphics.createImageBuffer(width, height, tile.getTransparentColor());
g = sheet.createGraphic();
}
final int x = number % horizontals;
final int y = (int) Math.floor(number / (double) horizontals);
g.drawImage(tile, x * tw, y * th);
number++;
if (number >= tilesPerSheet) {
g.dispose();
sheets.add(Drawable.loadSpriteTiled(Graphics.getImageBuffer(sheet), tw, th));
sheet = null;
g = null;
number = 0;
}
}
return sheets;
}
Aggregations