Search in sources :

Example 16 with SpriteTiled

use of com.b3dgs.lionengine.graphic.SpriteTiled in project lionengine by b3dgs.

the class SpriteTiledTest method testSetFade.

/**
 * Test set fade.
 */
@Test
public void testSetFade() {
    final SpriteTiled sprite = new SpriteTiledImpl(Graphics.createImageBuffer(64, 32), 16, 8);
    sprite.setFade(128, 128);
    sprite.setFade(128, 128);
    Assert.assertEquals(64, sprite.getWidth());
    Assert.assertEquals(32, sprite.getHeight());
}
Also used : SpriteTiled(com.b3dgs.lionengine.graphic.SpriteTiled) Test(org.junit.Test)

Example 17 with SpriteTiled

use of com.b3dgs.lionengine.graphic.SpriteTiled in project lionengine by b3dgs.

the class MapTileGameTest method testCreate.

/**
 * Test map creation.
 */
@Test
public void testCreate() {
    Assert.assertFalse(map.isCreated());
    map.create(16, 32, 2, 3);
    Assert.assertTrue(map.isCreated());
    map.loadSheets(new ArrayList<SpriteTiled>());
    Assert.assertEquals(16, map.getTileWidth());
    Assert.assertEquals(32, map.getTileHeight());
    Assert.assertEquals(2 * 16, map.getWidth());
    Assert.assertEquals(3 * 32, map.getHeight());
    Assert.assertEquals(2, map.getInTileWidth());
    Assert.assertEquals(3, map.getInTileHeight());
    Assert.assertEquals((int) Math.ceil(StrictMath.sqrt(2.0 * 2.0 + 3.0 * 3.0)), map.getInTileRadius());
    final Tile tile = map.createTile(Integer.valueOf(1), 2, 16.0, 32.0);
    Assert.assertEquals(1, tile.getSheet().intValue());
    Assert.assertEquals(2, tile.getNumber());
    Assert.assertEquals(16.0, tile.getX(), UtilTests.PRECISION);
    Assert.assertEquals(32.0, tile.getY(), UtilTests.PRECISION);
    Assert.assertEquals(1, tile.getInTileX());
    Assert.assertEquals(1, tile.getInTileY());
    Assert.assertEquals(16, tile.getWidth());
    Assert.assertEquals(32, tile.getHeight());
    Assert.assertEquals(1, tile.getInTileWidth());
    Assert.assertEquals(1, tile.getInTileHeight());
}
Also used : SpriteTiled(com.b3dgs.lionengine.graphic.SpriteTiled) Tile(com.b3dgs.lionengine.game.feature.tile.Tile) Test(org.junit.Test)

Example 18 with SpriteTiled

use of com.b3dgs.lionengine.graphic.SpriteTiled in project lionengine by b3dgs.

the class LevelRipConverter method checkTile.

/**
 * Check tile of sheet.
 *
 * @param map The destination map reference.
 * @param tileSprite The tiled sprite
 * @param sheet The sheet number.
 * @param x The location x.
 * @param y The location y.
 * @return The tile found.
 */
private static Tile checkTile(MapTile map, ImageBuffer tileSprite, Integer sheet, int x, int y) {
    final int tw = map.getTileWidth();
    final int th = map.getTileHeight();
    final SpriteTiled tileSheet = map.getSheet(sheet);
    final ImageBuffer sheetImage = tileSheet.getSurface();
    final int tilesInX = tileSheet.getWidth() / tw;
    final int tilesInY = tileSheet.getHeight() / th;
    for (int surfaceCurrentTileY = 0; surfaceCurrentTileY < tilesInY; surfaceCurrentTileY++) {
        for (int surfaceCurrentTileX = 0; surfaceCurrentTileX < tilesInX; surfaceCurrentTileX++) {
            // Tile number on tile sheet
            final int number = surfaceCurrentTileX + surfaceCurrentTileY * tilesInX;
            // Compare tiles between sheet and image map
            final int xa = x * tw;
            final int ya = y * th;
            final int xb = surfaceCurrentTileX * tw;
            final int yb = surfaceCurrentTileY * th;
            if (TilesExtractor.compareTile(tw, th, tileSprite, xa, ya, sheetImage, xb, yb)) {
                return map.createTile(sheet, number, xa, (map.getInTileHeight() - 1.0 - y) * th);
            }
        }
    }
    return null;
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) SpriteTiled(com.b3dgs.lionengine.graphic.SpriteTiled)

Example 19 with SpriteTiled

use of com.b3dgs.lionengine.graphic.SpriteTiled in project lionengine by b3dgs.

the class MapTileGame method loadSheets.

@Override
public void loadSheets(Media sheetsConfig) {
    this.sheetsConfig = sheetsConfig;
    final TileSheetsConfig config = TileSheetsConfig.imports(sheetsConfig);
    tileWidth = config.getTileWidth();
    tileHeight = config.getTileHeight();
    final String path = sheetsConfig.getPath();
    final String folder = path.substring(0, path.length() - sheetsConfig.getFile().getName().length());
    sheets.clear();
    int sheetId = 0;
    for (final String sheet : config.getSheets()) {
        final Media media = Medias.create(folder, sheet);
        final SpriteTiled sprite = Drawable.loadSpriteTiled(media, tileWidth, tileHeight);
        sprite.load();
        sprite.prepare();
        sheets.put(Integer.valueOf(sheetId), sprite);
        sheetId++;
    }
}
Also used : Media(com.b3dgs.lionengine.Media) SpriteTiled(com.b3dgs.lionengine.graphic.SpriteTiled)

Example 20 with SpriteTiled

use of com.b3dgs.lionengine.graphic.SpriteTiled in project lionengine by b3dgs.

the class MapTileRendererModel method renderTile.

/*
     * MapTileRenderer
     */
@Override
public void renderTile(Graphic g, MapTile map, 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.SpriteTiled)

Aggregations

SpriteTiled (com.b3dgs.lionengine.graphic.SpriteTiled)31 Test (org.junit.Test)24 ImageBuffer (com.b3dgs.lionengine.graphic.ImageBuffer)6 LionEngineException (com.b3dgs.lionengine.LionEngineException)1 Media (com.b3dgs.lionengine.Media)1 RasterImage (com.b3dgs.lionengine.core.RasterImage)1 FilterBilinear (com.b3dgs.lionengine.core.filter.FilterBilinear)1 Tile (com.b3dgs.lionengine.game.feature.tile.Tile)1 TileRef (com.b3dgs.lionengine.game.feature.tile.TileRef)1 ColorRgba (com.b3dgs.lionengine.graphic.ColorRgba)1 Graphic (com.b3dgs.lionengine.graphic.Graphic)1