Search in sources :

Example 16 with SpriteAnimated

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

the class SpriteAnimatedTest method testStretch.

/**
 * Test stretch sprite.
 */
@Test
public void testStretch() {
    final SpriteAnimated sprite = new SpriteAnimatedImpl(Graphics.createImageBuffer(64, 32), 16, 8);
    sprite.stretch(100.0, 100.0);
    Assert.assertEquals(64, sprite.getWidth());
    Assert.assertEquals(32, sprite.getHeight());
    Assert.assertEquals(4, sprite.getTileWidth());
    Assert.assertEquals(4, sprite.getTileHeight());
    sprite.stretch(200.0, 100.0);
    Assert.assertEquals(128, sprite.getWidth());
    Assert.assertEquals(32, sprite.getHeight());
    Assert.assertEquals(8, sprite.getTileWidth());
    Assert.assertEquals(4, sprite.getTileHeight());
    sprite.stretch(100.0, 200.0);
    Assert.assertEquals(128, sprite.getWidth());
    Assert.assertEquals(64, sprite.getHeight());
    Assert.assertEquals(8, sprite.getTileWidth());
    Assert.assertEquals(8, sprite.getTileHeight());
    sprite.stretch(200.0, 200.0);
    Assert.assertEquals(256, sprite.getWidth());
    Assert.assertEquals(128, sprite.getHeight());
    Assert.assertEquals(16, sprite.getTileWidth());
    Assert.assertEquals(16, sprite.getTileHeight());
}
Also used : SpriteAnimated(com.b3dgs.lionengine.graphic.SpriteAnimated) Test(org.junit.Test)

Example 17 with SpriteAnimated

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

the class SpriteAnimatedTest method testUpdateNoLoopReverse.

/**
 * Test update without loop but reverse.
 */
@Test
public void testUpdateNoLoopReverse() {
    final Animation animation = new Animation(Animation.DEFAULT_NAME, 1, 3, 1.0, true, false);
    final SpriteAnimated sprite = new SpriteAnimatedImpl(Graphics.createImageBuffer(64, 32), 16, 8);
    sprite.play(animation);
    Assert.assertEquals(AnimState.PLAYING, sprite.getAnimState());
    Assert.assertEquals(1, sprite.getFrame());
    Assert.assertEquals(1, sprite.getFrameAnim());
    sprite.update(1.0);
    Assert.assertEquals(AnimState.PLAYING, sprite.getAnimState());
    Assert.assertEquals(2, sprite.getFrame());
    Assert.assertEquals(2, sprite.getFrameAnim());
    sprite.update(1.0);
    Assert.assertEquals(AnimState.PLAYING, sprite.getAnimState());
    Assert.assertEquals(3, sprite.getFrame());
    Assert.assertEquals(3, sprite.getFrameAnim());
    sprite.update(1.0);
    Assert.assertEquals(AnimState.REVERSING, sprite.getAnimState());
    Assert.assertEquals(2, sprite.getFrame());
    Assert.assertEquals(2, sprite.getFrameAnim());
    sprite.update(1.0);
    Assert.assertEquals(AnimState.REVERSING, sprite.getAnimState());
    Assert.assertEquals(1, sprite.getFrame());
    Assert.assertEquals(1, sprite.getFrameAnim());
    sprite.update(1.0);
    Assert.assertEquals(AnimState.FINISHED, sprite.getAnimState());
    Assert.assertEquals(1, sprite.getFrame());
    Assert.assertEquals(1, sprite.getFrameAnim());
}
Also used : SpriteAnimated(com.b3dgs.lionengine.graphic.SpriteAnimated) Animation(com.b3dgs.lionengine.Animation) Test(org.junit.Test)

Example 18 with SpriteAnimated

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

the class SetupSurfaceRasteredTest method testConfigSmooth.

/**
 * Test the setup surface rastered config.
 */
@Test
public void testConfigSmooth() {
    final Media raster = Medias.create(RASTER_XML);
    final SetupSurfaceRastered setup = new SetupSurfaceRastered(Medias.create(OBJECT_SMOOTH_XML), raster);
    Assert.assertEquals(raster, setup.getFile());
    Assert.assertTrue(setup.hasSmooth());
    for (final SpriteAnimated sprite : setup.getRasters()) {
        Assert.assertEquals(setup.getSurface().getWidth(), sprite.getSurface().getWidth());
        Assert.assertEquals(setup.getSurface().getHeight(), sprite.getSurface().getHeight());
    }
    UtilFolder.deleteDirectory(Medias.create("void").getFile().getParentFile());
}
Also used : SpriteAnimated(com.b3dgs.lionengine.graphic.SpriteAnimated) Media(com.b3dgs.lionengine.Media) Test(org.junit.Test)

Example 19 with SpriteAnimated

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

the class SpriteAnimatedTest method testConstructorSurface.

/**
 * Test constructor with surface.
 */
@Test
public void testConstructorSurface() {
    final ImageBuffer surface = Graphics.createImageBuffer(64, 32);
    final SpriteAnimated sprite = new SpriteAnimatedImpl(surface, 16, 8);
    Assert.assertTrue(sprite.isLoaded());
    Assert.assertEquals(surface, sprite.getSurface());
    Assert.assertEquals(64, sprite.getWidth());
    Assert.assertEquals(32, sprite.getHeight());
    Assert.assertEquals(4, sprite.getTileWidth());
    Assert.assertEquals(4, sprite.getTileHeight());
    Assert.assertEquals(16, sprite.getFramesHorizontal());
    Assert.assertEquals(8, sprite.getFramesVertical());
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) SpriteAnimated(com.b3dgs.lionengine.graphic.SpriteAnimated) Test(org.junit.Test)

Example 20 with SpriteAnimated

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

the class SpriteAnimatedTest method testStretchInvalidWidth.

/**
 * Test stretch sprite with invalid width.
 */
@Test(expected = LionEngineException.class)
public void testStretchInvalidWidth() {
    final SpriteAnimated sprite = new SpriteAnimatedImpl(Graphics.createImageBuffer(64, 32), 16, 8);
    sprite.stretch(0.0, 100.0);
}
Also used : SpriteAnimated(com.b3dgs.lionengine.graphic.SpriteAnimated) Test(org.junit.Test)

Aggregations

SpriteAnimated (com.b3dgs.lionengine.graphic.SpriteAnimated)33 Test (org.junit.Test)33 Animation (com.b3dgs.lionengine.Animation)6 ImageBuffer (com.b3dgs.lionengine.graphic.ImageBuffer)3 Media (com.b3dgs.lionengine.Media)1 FilterBilinear (com.b3dgs.lionengine.core.filter.FilterBilinear)1 Graphic (com.b3dgs.lionengine.graphic.Graphic)1