Search in sources :

Example 1 with Transparency

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

the class FactoryGraphicAwt method generateTileset.

@Override
public void generateTileset(ImageBuffer[] images, Media media) {
    Check.notNull(images);
    Check.notNull(media);
    if (images.length == 0) {
        throw new LionEngineException("No images found !");
    }
    final int width = images[0].getWidth();
    final int height = images[0].getHeight();
    final Transparency transparency = images[0].getTransparency();
    final int multDistance = (int) Math.ceil(width * images.length / (double) height) / 4;
    final int[] mult = UtilMath.getClosestSquareMult(images.length, multDistance);
    final ImageBuffer tile = new ImageBufferAwt(ToolsAwt.createImage(width * mult[1], height * mult[0], ToolsAwt.getTransparency(transparency)));
    int x = 0;
    int y = 0;
    int line = 0;
    final Graphic g = tile.createGraphic();
    for (final ImageBuffer b : images) {
        g.drawImage(b, x, y);
        x += b.getWidth();
        line++;
        if (line == mult[1]) {
            x = 0;
            y += b.getHeight();
            line = 0;
        }
    }
    g.dispose();
    saveImage(tile, media);
}
Also used : Transparency(com.b3dgs.lionengine.graphic.Transparency) ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) LionEngineException(com.b3dgs.lionengine.LionEngineException) Graphic(com.b3dgs.lionengine.graphic.Graphic) FactoryGraphic(com.b3dgs.lionengine.graphic.FactoryGraphic)

Aggregations

LionEngineException (com.b3dgs.lionengine.LionEngineException)1 FactoryGraphic (com.b3dgs.lionengine.graphic.FactoryGraphic)1 Graphic (com.b3dgs.lionengine.graphic.Graphic)1 ImageBuffer (com.b3dgs.lionengine.graphic.ImageBuffer)1 Transparency (com.b3dgs.lionengine.graphic.Transparency)1