Search in sources :

Example 26 with ImageBuffer

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

the class RasterableModel method setRaster.

@Override
public void setRaster(boolean save, Media media, int rasterHeight, Collection<Integer> allowed) {
    if (setupRastered.isExtern()) {
        Check.notNull(media);
        Check.superiorStrict(rasterHeight, 0);
        this.media = Optional.of(media);
        this.rasterHeight = rasterHeight;
        setupRastered.load(save, media, allowed);
        rastersAnim.clear();
        count = -1;
        final List<ImageBuffer> buffers = setupRastered.getRasters();
        final int n = buffers.size();
        for (int i = 0; i < n; i++) {
            final SpriteAnimated sprite = Drawable.loadSpriteAnimated(buffers.get(i), raster.getFramesHorizontal(), raster.getFramesVertical());
            rastersAnim.add(sprite);
            count++;
        }
        if (rastersAnim.size() < 2) {
            updater = UpdatableVoid.getInstance();
        } else {
            updater = extrp -> updateRasterAnim();
        }
    }
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) SpriteAnimated(com.b3dgs.lionengine.graphic.drawable.SpriteAnimated)

Example 27 with ImageBuffer

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

the class ImageBufferHeadlessTest method testImage.

/**
 * Test image.
 */
@Test
void testImage() {
    final ImageBuffer image = new ImageBufferHeadless(100, 100, Transparency.OPAQUE);
    assertNotNull(image.createGraphic());
    image.prepare();
    assertEquals(ColorRgba.TRANSPARENT.getRgba(), image.getRgb(0, 0));
    assertNotNull(image.getRgb(0, 0, 1, 1, new int[1], 0, 0));
    assertEquals(Transparency.OPAQUE, image.getTransparency());
    assertEquals(Transparency.OPAQUE, new ImageBufferHeadless(100, 100, Transparency.OPAQUE).getTransparency());
    assertEquals(100, image.getWidth());
    assertEquals(100, image.getHeight());
    image.setRgb(0, 0, ColorRgba.BLUE.getRgba());
    assertEquals(ColorRgba.BLUE.getRgba(), image.getRgb(0, 0));
    image.setRgb(0, 0, 0, 0, new int[1], 0, 0);
    image.dispose();
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Test(org.junit.jupiter.api.Test)

Example 28 with ImageBuffer

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

the class GraphicHeadlessTest method testApplyMask.

/**
 * Test apply mask.
 */
@Test
void testApplyMask() {
    final ImageBuffer image = Graphics.createImageBuffer(10, 20);
    assertEquals(ColorRgba.BLACK.getRgba(), Graphics.applyMask(image, ColorRgba.TRANSPARENT).getRgb(0, 0));
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Test(org.junit.jupiter.api.Test) GraphicTest(com.b3dgs.lionengine.graphic.GraphicTest)

Example 29 with ImageBuffer

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

the class TextHeadlessTest method beforeTests.

/**
 * Setup tests.
 */
@BeforeAll
public static void beforeTests() {
    Graphics.setFactoryGraphic(new FactoryGraphicHeadless());
    final ImageBuffer buffer = Graphics.createImageBuffer(320, 240);
    buffer.prepare();
    g = buffer.createGraphic();
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 30 with ImageBuffer

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

the class SpriteDigitTest method testEquals.

/**
 * Test equals.
 */
@Test
void testEquals() {
    final ImageBuffer surface = Graphics.createImageBuffer(64, 32);
    final SpriteDigit sprite = new SpriteDigitImpl(surface, 1, 1, 1);
    final Media media = Medias.create("image.png");
    final SpriteDigit spriteMedia = new SpriteDigitImpl(media, 1, 1, 1);
    assertEquals(sprite, sprite);
    assertEquals(sprite, new SpriteDigitImpl(surface, 1, 1, 1));
    assertEquals(spriteMedia, spriteMedia);
    assertNotEquals(sprite, null);
    assertNotEquals(sprite, new Object());
    assertNotEquals(sprite, new SpriteDigitImpl(media, 1, 1, 1));
    assertNotEquals(spriteMedia, new SpriteDigitImpl(media, 1, 1, 1));
    assertNotEquals(sprite, new SpriteDigitImpl(Graphics.createImageBuffer(64, 32), 1, 1, 1));
    assertNotEquals(sprite, new SpriteDigitImpl(Graphics.createImageBuffer(32, 32), 1, 1, 1));
    assertNotEquals(sprite, new SpriteDigitImpl(Graphics.createImageBuffer(64, 64), 1, 1, 1));
    assertNotEquals(sprite, new SpriteDigitImpl(Graphics.createImageBuffer(32, 64), 1, 1, 1));
    sprite.dispose();
    spriteMedia.dispose();
    surface.dispose();
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Media(com.b3dgs.lionengine.Media) Test(org.junit.jupiter.api.Test)

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