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());
}
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());
}
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;
}
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++;
}
}
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);
}
Aggregations