Search in sources :

Example 6 with Graphic

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

the class SpriteFontTest method testDraw.

/**
 * Test draw.
 */
@Test
public void testDraw() {
    final Graphic g = Graphics.createImageBuffer(100, 100).createGraphic();
    try {
        final SpriteFont sprite = new SpriteFontImpl(media, font, 6, 7);
        sprite.load();
        sprite.draw(g, 1, 2, Align.CENTER, "az%");
    } finally {
        g.dispose();
    }
}
Also used : SpriteFont(com.b3dgs.lionengine.graphic.SpriteFont) Graphic(com.b3dgs.lionengine.graphic.Graphic) Test(org.junit.Test)

Example 7 with Graphic

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

the class TilesExtractor method extract.

/**
 * Extract the tile from level.
 *
 * @param level The level image reference.
 * @param number The tile number on level.
 * @return The extracted tile image from level.
 */
private static ImageBuffer extract(SpriteTiled level, int number) {
    final ColorRgba transparency = level.getSurface().getTransparentColor();
    final ImageBuffer tile = Graphics.createImageBuffer(level.getTileWidth(), level.getTileHeight(), transparency);
    final Graphic g = tile.createGraphic();
    level.setTile(number);
    level.render(g);
    g.dispose();
    final ImageBuffer copy = Graphics.getImageBuffer(tile);
    tile.dispose();
    return copy;
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba) Graphic(com.b3dgs.lionengine.graphic.Graphic)

Example 8 with Graphic

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

the class Minimap method prepare.

/**
 * Fill minimap surface with tile color configuration.
 *
 * @throws LionEngineException If surface has not been loaded ({@link #load()} may have not been called).
 */
@Override
public void prepare() {
    if (surface == null) {
        throw new LionEngineException(ERROR_SURFACE);
    }
    final Graphic g = surface.createGraphic();
    final int v = map.getInTileHeight();
    final int h = map.getInTileWidth();
    for (int ty = 0; ty < v; ty++) {
        for (int tx = 0; tx < h; tx++) {
            final Tile tile = map.getTile(tx, ty);
            final ColorRgba color = getTileColor(tile);
            if (!NO_TILE.equals(color)) {
                g.setColor(color);
                g.drawRect(tx, v - ty - 1, 0, 0, false);
            }
        }
    }
    g.dispose();
}
Also used : ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba) LionEngineException(com.b3dgs.lionengine.LionEngineException) Graphic(com.b3dgs.lionengine.graphic.Graphic) Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Example 9 with Graphic

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

the class SpriteDigitTest method testRender.

/**
 * Test render.
 */
@Test
void testRender() {
    final Graphic g = Graphics.createImageBuffer(100, 100).createGraphic();
    final SpriteDigit sprite = new SpriteDigitImpl(Graphics.createImageBuffer(64, 32), 1, 1, 1);
    sprite.render(g);
    sprite.setMirror(Mirror.HORIZONTAL);
    sprite.render(g);
    sprite.setMirror(Mirror.VERTICAL);
    sprite.render(g);
    g.dispose();
}
Also used : Graphic(com.b3dgs.lionengine.graphic.Graphic) Test(org.junit.jupiter.api.Test)

Example 10 with Graphic

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

the class SpriteTiledTest method testRender.

/**
 * Test render.
 */
@Test
void testRender() {
    final Graphic g = Graphics.createImageBuffer(100, 100).createGraphic();
    try {
        final SpriteTiled sprite = new SpriteTiledImpl(Graphics.createImageBuffer(64, 32), 16, 8);
        sprite.render(g);
        sprite.setTile(0);
        sprite.setMirror(Mirror.HORIZONTAL);
        sprite.render(g);
        sprite.setMirror(Mirror.VERTICAL);
        sprite.render(g);
    } finally {
        g.dispose();
    }
}
Also used : Graphic(com.b3dgs.lionengine.graphic.Graphic) Test(org.junit.jupiter.api.Test)

Aggregations

Graphic (com.b3dgs.lionengine.graphic.Graphic)45 Test (org.junit.jupiter.api.Test)18 ImageBuffer (com.b3dgs.lionengine.graphic.ImageBuffer)12 FactoryGraphic (com.b3dgs.lionengine.graphic.FactoryGraphic)9 Test (org.junit.Test)8 BufferedImage (java.awt.image.BufferedImage)5 GraphicMock (com.b3dgs.lionengine.graphic.GraphicMock)4 LionEngineException (com.b3dgs.lionengine.LionEngineException)3 Resolution (com.b3dgs.lionengine.Resolution)3 FactoryGraphicMock (com.b3dgs.lionengine.graphic.FactoryGraphicMock)3 Media (com.b3dgs.lionengine.Media)2 ColorRgba (com.b3dgs.lionengine.graphic.ColorRgba)2 SpriteFont (com.b3dgs.lionengine.graphic.SpriteFont)2 Text (com.b3dgs.lionengine.graphic.Text)2 Align (com.b3dgs.lionengine.Align)1 Surface (com.b3dgs.lionengine.Surface)1 Tile (com.b3dgs.lionengine.game.feature.tile.Tile)1 Image (com.b3dgs.lionengine.graphic.Image)1 Sprite (com.b3dgs.lionengine.graphic.Sprite)1 SpriteAnimated (com.b3dgs.lionengine.graphic.SpriteAnimated)1