Search in sources :

Example 1 with SpriteTiled

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;
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) ArrayList(java.util.ArrayList) Media(com.b3dgs.lionengine.Media) SpriteTiled(com.b3dgs.lionengine.graphic.drawable.SpriteTiled)

Example 2 with SpriteTiled

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);
}
Also used : SpriteTiled(com.b3dgs.lionengine.graphic.drawable.SpriteTiled)

Example 3 with SpriteTiled

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;
}
Also used : MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) SpriteTiled(com.b3dgs.lionengine.graphic.drawable.SpriteTiled)

Example 4 with SpriteTiled

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++;
        }
    }
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba) SpriteTiled(com.b3dgs.lionengine.graphic.drawable.SpriteTiled)

Example 5 with SpriteTiled

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;
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Graphic(com.b3dgs.lionengine.graphic.Graphic) SpriteTiled(com.b3dgs.lionengine.graphic.drawable.SpriteTiled) ArrayList(java.util.ArrayList) Surface(com.b3dgs.lionengine.Surface)

Aggregations

SpriteTiled (com.b3dgs.lionengine.graphic.drawable.SpriteTiled)12 ImageBuffer (com.b3dgs.lionengine.graphic.ImageBuffer)5 Media (com.b3dgs.lionengine.Media)3 ArrayList (java.util.ArrayList)2 Surface (com.b3dgs.lionengine.Surface)1 Tile (com.b3dgs.lionengine.game.feature.tile.Tile)1 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)1 ColorRgba (com.b3dgs.lionengine.graphic.ColorRgba)1 Graphic (com.b3dgs.lionengine.graphic.Graphic)1 RasterImage (com.b3dgs.lionengine.graphic.raster.RasterImage)1 Test (org.junit.jupiter.api.Test)1