use of com.b3dgs.lionengine.graphic.Graphic in project lionengine by b3dgs.
the class FactoryGraphicHeadless method createImageBuffer.
@Override
public ImageBuffer createImageBuffer(int width, int height) {
final ImageBuffer buffer = new ImageBufferHeadless(width, height, Transparency.OPAQUE);
final Graphic g = buffer.createGraphic();
g.setColor(ColorRgba.BLACK);
g.drawRect(0, 0, width, height, true);
g.dispose();
return buffer;
}
use of com.b3dgs.lionengine.graphic.Graphic in project lionengine by b3dgs.
the class SheetsExtractor method extract.
/**
* Convert a set of tile to a set of tile sheets.
*
* @param tiles The list of tiles.
* @param horizontalTiles The number of horizontal tiles on sheet (inferior or equal to 0 to use automatic).
* @return The list of tile sheets.
*/
public static List<SpriteTiled> extract(Collection<ImageBuffer> tiles, int horizontalTiles) {
final Surface surface = getSheetSize(tiles, horizontalTiles);
final int horizontals = surface.getWidth();
final int verticals = surface.getHeight();
final int tilesPerSheet = Math.min(tiles.size(), horizontals * verticals);
final List<SpriteTiled> sheets = new ArrayList<>();
ImageBuffer sheet = null;
Graphic g = null;
int number = 0;
int tw = 0;
int th = 0;
for (final ImageBuffer tile : tiles) {
if (g == null) {
tw = tile.getWidth();
th = tile.getHeight();
final int width = Math.max(tw, horizontals * tw);
final int height = Math.max(th, verticals * th);
sheet = Graphics.createImageBuffer(width, height, tile.getTransparentColor());
g = sheet.createGraphic();
}
final int x = number % horizontals;
final int y = (int) Math.floor(number / (double) horizontals);
g.drawImage(tile, x * tw, y * th);
number++;
if (number >= tilesPerSheet) {
g.dispose();
sheets.add(Drawable.loadSpriteTiled(Graphics.getImageBuffer(sheet), tw, th));
sheet = null;
g = null;
number = 0;
}
}
return sheets;
}
use of com.b3dgs.lionengine.graphic.Graphic in project lionengine by b3dgs.
the class CollidableModelTest method testRender.
/**
* Test collidable rendering.
*/
@Test
void testRender() {
transformable1.moveLocation(1.0, 1.0, 1.0);
final Graphic g = Graphics.createGraphic();
collidable1.setOrigin(Origin.MIDDLE);
collidable1.render(g);
final Collision collision = new Collision("test", 0, 0, 3, 3, false);
collidable1.addCollision(collision);
collidable1.addCollision(Collision.AUTOMATIC);
collidable1.setCollisionVisibility(true);
transformable1.teleport(1.0, 1.0);
transformable1.moveLocation(1.0, 1.0, 1.0);
collidable1.setEnabled(false);
collidable1.render(g);
collidable1.setEnabled(true);
collidable1.render(g);
}
use of com.b3dgs.lionengine.graphic.Graphic 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);
}
use of com.b3dgs.lionengine.graphic.Graphic in project lionengine by b3dgs.
the class FactoryGraphicAwt method createImageBuffer.
@Override
public ImageBuffer createImageBuffer(int width, int height, ColorRgba transparency) {
Check.notNull(transparency);
final BufferedImage image = ToolsAwt.createImage(width, height, java.awt.Transparency.BITMASK);
final ImageBuffer buffer = new ImageBufferAwt(image);
final Graphic g = buffer.createGraphic();
g.setColor(transparency);
g.drawRect(0, 0, width, height, true);
g.dispose();
return buffer;
}
Aggregations