Search in sources :

Example 66 with ImageBuffer

use of com.b3dgs.lionengine.graphic.ImageBuffer 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;
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Graphic(com.b3dgs.lionengine.graphic.Graphic) FactoryGraphic(com.b3dgs.lionengine.graphic.FactoryGraphic) BufferedImage(java.awt.image.BufferedImage)

Example 67 with ImageBuffer

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

the class FactoryGraphicAwtTest method testRotate.

/*
     * FactoryGraphicTest
     */
/**
 * Test rotate.
 */
@Test
@Override
public void testRotate() {
    final ImageBuffer rotate = Graphics.rotate(image, 90);
    Assert.assertNotEquals(image, rotate);
    Assert.assertEquals(image.getWidth(), rotate.getHeight());
    Assert.assertEquals(image.getHeight(), rotate.getWidth());
    rotate.dispose();
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) FactoryGraphicTest(com.b3dgs.lionengine.graphic.FactoryGraphicTest) Test(org.junit.Test)

Example 68 with ImageBuffer

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

the class ImageBufferAwtTest method testImageTransparency.

/**
 * Test image transparency
 */
@Test
public void testImageTransparency() {
    final ImageBuffer image = Graphics.createImageBuffer(100, 100, ColorRgba.RED);
    Assert.assertEquals(Transparency.BITMASK, image.getTransparency());
    Assert.assertEquals(ColorRgba.TRANSPARENT, image.getTransparentColor());
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Test(org.junit.Test)

Example 69 with ImageBuffer

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

the class TextAwtTest method setUp.

/**
 * Setup test.
 */
@BeforeClass
public static void setUp() {
    Graphics.setFactoryGraphic(new FactoryGraphicAwt());
    final ImageBuffer buffer = Graphics.createImageBuffer(320, 240);
    buffer.prepare();
    g = buffer.createGraphic();
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) BeforeClass(org.junit.BeforeClass)

Example 70 with ImageBuffer

use of com.b3dgs.lionengine.graphic.ImageBuffer 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;
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) SpriteTiled(com.b3dgs.lionengine.graphic.SpriteTiled)

Aggregations

ImageBuffer (com.b3dgs.lionengine.graphic.ImageBuffer)110 Test (org.junit.Test)34 Test (org.junit.jupiter.api.Test)28 Media (com.b3dgs.lionengine.Media)16 Graphic (com.b3dgs.lionengine.graphic.Graphic)12 GraphicTest (com.b3dgs.lionengine.graphic.GraphicTest)12 FactoryGraphic (com.b3dgs.lionengine.graphic.FactoryGraphic)9 BufferedImage (java.awt.image.BufferedImage)9 SpriteTiled (com.b3dgs.lionengine.graphic.SpriteTiled)6 SpriteTiled (com.b3dgs.lionengine.graphic.drawable.SpriteTiled)5 ColorRgba (com.b3dgs.lionengine.graphic.ColorRgba)3 FactoryGraphicTest (com.b3dgs.lionengine.graphic.FactoryGraphicTest)3 Image (com.b3dgs.lionengine.graphic.Image)3 Sprite (com.b3dgs.lionengine.graphic.Sprite)3 SpriteAnimated (com.b3dgs.lionengine.graphic.SpriteAnimated)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 TilesExtractor (com.b3dgs.lionengine.game.feature.tile.TilesExtractor)2 ArrayList (java.util.ArrayList)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 Config (com.b3dgs.lionengine.Config)1