use of com.b3dgs.lionengine.graphic.drawable.Sprite in project lionengine by b3dgs.
the class LevelRipConverter method start.
/**
* Run the converter.
*
* @param levelrip The file containing the levelrip as an image.
* @param map The destination map reference.
* @param listener The progress listener.
* @param canceler The canceler reference.
* @return The total number of not found tiles.
* @throws LionEngineException If media is <code>null</code> or image cannot be read.
*/
public static int start(Media levelrip, MapTile map, ProgressListener listener, Canceler canceler) {
final Sprite imageMap = Drawable.loadSprite(levelrip);
imageMap.load();
imageMap.prepare();
final int imageTilesInX = imageMap.getWidth() / map.getTileWidth();
final int imageTilesInY = imageMap.getHeight() / map.getTileHeight();
map.create(map.getTileWidth(), map.getTileHeight(), imageTilesInX, imageTilesInY);
final double progressMax = imageTilesInX * (double) imageTilesInY;
long progress = 0L;
int lastPercent = 0;
int errors = 0;
final ImageBuffer tileRef = imageMap.getSurface();
for (int progressTileY = 0; progressTileY < imageTilesInY; progressTileY++) {
for (int progressTileX = 0; progressTileX < imageTilesInX; progressTileX++) {
if (!checkPixel(map, tileRef, progressTileX, progressTileY)) {
Verbose.warning("Tile missing at: " + progressTileX + " " + progressTileY);
errors++;
}
final int percent = (int) Math.round(progress / progressMax * 100);
if (listener != null && percent != lastPercent) {
listener.notifyProgress(percent, progressTileX, progressTileY);
}
lastPercent = percent;
progress++;
if (canceler != null && canceler.isCanceled()) {
tileRef.dispose();
return errors;
}
}
}
tileRef.dispose();
return errors;
}
use of com.b3dgs.lionengine.graphic.drawable.Sprite in project lionengine by b3dgs.
the class BackgroundAbstract method createSprite.
/**
* Create a sprite from its filename.
*
* @param media The sprite media.
* @return The sprite instance.
* @throws LionEngineException If media is <code>null</code> or image cannot be read.
*/
protected static Sprite createSprite(Media media) {
final Sprite sprite = Drawable.loadSprite(media);
sprite.load();
sprite.prepare();
return sprite;
}
Aggregations