Search in sources :

Example 1 with TilesExtractor

use of com.b3dgs.lionengine.game.feature.tile.TilesExtractor in project lionengine by b3dgs.

the class Scene method load.

@Override
public void load() {
    final Media levelrip = Medias.create("level.png");
    final TilesExtractor tilesExtractor = new TilesExtractor();
    final AtomicInteger p = new AtomicInteger();
    tilesExtractor.addListener((percent, tiles) -> p.set(percent));
    Collection<ImageBuffer> buffers = tilesExtractor.extract(16, 16, Arrays.asList(levelrip));
    map.loadSheets(SheetsExtractor.extract(buffers, 16));
    buffers.forEach(ImageBuffer::dispose);
    assertEquals(100, p.get());
    p.set(0);
    tilesExtractor.addListener((percent, tiles) -> p.set(percent));
    buffers = tilesExtractor.extract(() -> true, 16, 16, Arrays.asList(levelrip));
    map.loadSheets(SheetsExtractor.extract(buffers, 16));
    buffers.forEach(ImageBuffer::dispose);
    assertEquals(0, p.get());
    tilesExtractor.addListener((percent, tiles) -> p.set(percent));
    buffers = tilesExtractor.extract(() -> false, 16, 16, Arrays.asList(levelrip));
    map.loadSheets(SheetsExtractor.extract(buffers, 16));
    buffers.forEach(ImageBuffer::dispose);
    assertEquals(100, p.get());
    p.set(0);
    LevelRipConverter.start(levelrip, map, (percent, progressTileX, progressTileY) -> p.set(percent));
    assertEquals(100, p.get());
    mapViewer.prepare(map);
    minimap.load();
    minimap.automaticColor();
    minimap.prepare();
    camera.setView(0, 0, getWidth(), getHeight(), getHeight());
    camera.setLimits(map);
    tick.start();
}
Also used : TilesExtractor(com.b3dgs.lionengine.game.feature.tile.TilesExtractor) ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Media(com.b3dgs.lionengine.Media)

Example 2 with TilesExtractor

use of com.b3dgs.lionengine.game.feature.tile.TilesExtractor in project lionengine by b3dgs.

the class MapTileGame method create.

/**
 * Create a map from a level rip which should be an image file (*.PNG, *.BMP) that represents the full map.
 * The file will be read pixel by pixel to recognize tiles and their location. Data structure will be created (
 * {@link #create(int, int, int, int)}).
 *
 * @param levelrip The file describing the levelrip as a single image.
 * @param tileWidth The tile width.
 * @param tileHeight The tile height.
 * @param horizontalTiles The number of horizontal tiles on sheets.
 * @throws LionEngineException If error when importing map.
 * @see TilesExtractor
 * @see LevelRipConverter
 */
public void create(Media levelrip, int tileWidth, int tileHeight, int horizontalTiles) {
    final TilesExtractor tilesExtractor = new TilesExtractor();
    final Collection<ImageBuffer> buffers = tilesExtractor.extract(tileWidth, tileHeight, Arrays.asList(levelrip));
    loadSheets(SheetsExtractor.extract(buffers, horizontalTiles));
    for (final ImageBuffer tileBuffer : buffers) {
        tileBuffer.dispose();
    }
    LevelRipConverter.start(levelrip, mapSurface);
}
Also used : TilesExtractor(com.b3dgs.lionengine.game.feature.tile.TilesExtractor) ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer)

Aggregations

TilesExtractor (com.b3dgs.lionengine.game.feature.tile.TilesExtractor)2 ImageBuffer (com.b3dgs.lionengine.graphic.ImageBuffer)2 Media (com.b3dgs.lionengine.Media)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1