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