Search in sources :

Example 1 with SpriteTiled

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

the class MapTileGame method loadSheets.

@Override
public void loadSheets(Collection<SpriteTiled> sheets) {
    int sheetId = 0;
    for (final SpriteTiled sheet : sheets) {
        this.sheets.put(Integer.valueOf(sheetId), sheet);
        if ((tileWidth != 0 || tileHeight != 0) && tileWidth != sheet.getTileWidth() && tileHeight != sheet.getTileHeight()) {
            throw new LionEngineException(ERROR_TILE_SIZE);
        }
        tileWidth = sheet.getTileWidth();
        tileHeight = sheet.getTileHeight();
        sheetId++;
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) SpriteTiled(com.b3dgs.lionengine.graphic.SpriteTiled)

Example 2 with SpriteTiled

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

the class Minimap method computeSheet.

/**
 * Compute the current sheet.
 *
 * @param colors The colors data.
 * @param sheet The sheet number.
 */
private void computeSheet(Map<TileRef, ColorRgba> colors, Integer sheet) {
    final SpriteTiled tiles = map.getSheet(sheet);
    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(new TileRef(sheet, number), color);
            }
            number++;
        }
    }
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba) SpriteTiled(com.b3dgs.lionengine.graphic.SpriteTiled) TileRef(com.b3dgs.lionengine.game.feature.tile.TileRef)

Example 3 with SpriteTiled

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

the class SpriteTiledTest method testRotate.

/**
 * Test rotate sprite.
 */
@Test
public void testRotate() {
    final SpriteTiled sprite = new SpriteTiledImpl(Graphics.createImageBuffer(64, 32), 16, 8);
    for (int angle = -720; angle < 720; angle++) {
        sprite.rotate(angle);
        Assert.assertTrue(angle + Constant.SPACE + sprite.getWidth(), sprite.getWidth() >= 64);
        Assert.assertTrue(angle + Constant.SPACE + sprite.getHeight(), sprite.getHeight() >= 32);
    }
}
Also used : SpriteTiled(com.b3dgs.lionengine.graphic.SpriteTiled) Test(org.junit.Test)

Example 4 with SpriteTiled

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

the class SpriteTiledTest method testConstructorMedia.

/**
 * Test constructor with media.
 */
@Test
public void testConstructorMedia() {
    final SpriteTiled sprite = new SpriteTiledImpl(media, 16, 8);
    Assert.assertFalse(sprite.isLoaded());
    Assert.assertNull(sprite.getSurface());
    Assert.assertEquals(64, sprite.getWidth());
    Assert.assertEquals(32, sprite.getHeight());
    Assert.assertEquals(16, sprite.getTileWidth());
    Assert.assertEquals(8, sprite.getTileHeight());
    Assert.assertEquals(4, sprite.getTilesHorizontal());
    Assert.assertEquals(4, sprite.getTilesVertical());
}
Also used : SpriteTiled(com.b3dgs.lionengine.graphic.SpriteTiled) Test(org.junit.Test)

Example 5 with SpriteTiled

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

the class SpriteTiledTest method testSetAlphaHigh.

/**
 * Test set alpha too high.
 */
@Test(expected = LionEngineException.class)
public void testSetAlphaHigh() {
    final SpriteTiled sprite = new SpriteTiledImpl(Graphics.createImageBuffer(64, 32), 16, 8);
    sprite.setAlpha(256);
}
Also used : SpriteTiled(com.b3dgs.lionengine.graphic.SpriteTiled) Test(org.junit.Test)

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