Search in sources :

Example 1 with SpriteParallaxed

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

the class SpriteParallaxedTest method testParallax.

/**
 * Test parallax sprite.
 */
@SuppressWarnings("unlikely-arg-type")
@Test
public void testParallax() {
    final ImageHeader info = ImageInfo.get(media);
    final SpriteParallaxed spriteA = Drawable.loadSpriteParallaxed(media, LINES, 60, 100);
    spriteA.load(false);
    Assert.assertTrue(spriteA.equals(spriteA));
    Assert.assertEquals(info.getHeight() / LINES, spriteA.getHeight());
    Assert.assertEquals(38, spriteA.getWidth());
    Assert.assertEquals(41, spriteA.getLineWidth(2));
    // Test render
    spriteA.render(g, 0, 0, 0);
    // Resize
    final SpriteParallaxed spriteB = Drawable.loadSpriteParallaxed(media, LINES, 60, 100);
    spriteB.stretch(200, 100);
    spriteB.load(true);
    Assert.assertFalse(spriteB.equals(spriteA));
    Assert.assertTrue(spriteA.hashCode() != spriteB.hashCode());
    Assert.assertFalse(spriteA.equals(media));
    final SpriteParallaxed spriteC = Drawable.loadSpriteParallaxed(media, LINES, 60, 100);
    spriteC.stretch(100, 200);
    spriteC.load(true);
    Assert.assertFalse(spriteC.equals(spriteA));
    Assert.assertTrue(spriteA.hashCode() != spriteC.hashCode());
    Assert.assertFalse(spriteA.equals(media));
}
Also used : SpriteParallaxed(com.b3dgs.lionengine.graphic.SpriteParallaxed) ImageHeader(com.b3dgs.lionengine.graphic.ImageHeader) Test(org.junit.Test)

Example 2 with SpriteParallaxed

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

the class SpriteParallaxedTest method testParallaxFailure.

/**
 * Test parallax sprite failure.
 */
@Test
public void testParallaxFailure() {
    try {
        final SpriteParallaxed spriteC = Drawable.loadSpriteParallaxed(media, 0, 60, 100);
        Assert.assertNotNull(spriteC);
        Assert.fail();
    } catch (final LionEngineException exception) {
        // Success
        Assert.assertNotNull(exception);
    }
    try {
        final SpriteParallaxed spriteC = Drawable.loadSpriteParallaxed(media, LINES, 60, 0);
        Assert.assertNotNull(spriteC);
        Assert.fail();
    } catch (final LionEngineException exception) {
        // Success
        Assert.assertNotNull(exception);
    }
    try {
        final SpriteParallaxed spriteC = Drawable.loadSpriteParallaxed(media, LINES, 0, 60);
        Assert.assertNotNull(spriteC);
        Assert.fail();
    } catch (final LionEngineException exception) {
        // Success
        Assert.assertNotNull(exception);
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) SpriteParallaxed(com.b3dgs.lionengine.graphic.SpriteParallaxed) Test(org.junit.Test)

Aggregations

SpriteParallaxed (com.b3dgs.lionengine.graphic.SpriteParallaxed)2 Test (org.junit.Test)2 LionEngineException (com.b3dgs.lionengine.LionEngineException)1 ImageHeader (com.b3dgs.lionengine.graphic.ImageHeader)1