Search in sources :

Example 6 with Animation

use of com.b3dgs.lionengine.Animation in project lionengine by b3dgs.

the class SpriteAnimatedTest method testUpdateLoopReverse.

/**
 * Test update with loop and reverse.
 */
@Test
public void testUpdateLoopReverse() {
    final Animation animation = new Animation(Animation.DEFAULT_NAME, 1, 3, 1.0, true, true);
    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.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());
}
Also used : SpriteAnimated(com.b3dgs.lionengine.graphic.SpriteAnimated) Animation(com.b3dgs.lionengine.Animation) Test(org.junit.Test)

Example 7 with Animation

use of com.b3dgs.lionengine.Animation in project lionengine by b3dgs.

the class SpriteAnimatedTest method testSetSpeed.

/**
 * Test set speed.
 */
@Test
public void testSetSpeed() {
    final Animation animation = new Animation(Animation.DEFAULT_NAME, 1, 3, 1.0, false, false);
    final SpriteAnimated sprite = new SpriteAnimatedImpl(Graphics.createImageBuffer(64, 32), 16, 8);
    sprite.play(animation);
    sprite.setAnimSpeed(2.0);
    sprite.update(1.0);
    Assert.assertEquals(AnimState.PLAYING, sprite.getAnimState());
    Assert.assertEquals(3, sprite.getFrame());
    Assert.assertEquals(3, sprite.getFrameAnim());
}
Also used : SpriteAnimated(com.b3dgs.lionengine.graphic.SpriteAnimated) Animation(com.b3dgs.lionengine.Animation) Test(org.junit.Test)

Example 8 with Animation

use of com.b3dgs.lionengine.Animation 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 9 with Animation

use of com.b3dgs.lionengine.Animation in project lionengine by b3dgs.

the class RasterableModel method updateRaster.

/**
 * Update raster.
 */
private void updateRaster() {
    if (transform != null) {
        final Animation anim = animatable.getAnim();
        if (anim != null) {
            raster.setFrame(transform.transform(anim.getName(), animatable.getFrameAnim()));
        }
    } else {
        raster.setFrame(animatable.getFrame() + animOffset + animOffset2);
    }
    raster.setMirror(mirrorable.getMirror());
    raster.setOrigin(origin);
    raster.setFrameOffsets(frameOffsetX, frameOffsetY);
}
Also used : Animation(com.b3dgs.lionengine.Animation)

Example 10 with Animation

use of com.b3dgs.lionengine.Animation in project lionengine by b3dgs.

the class SpriteAnimatedTest method testAnimatorListener.

/**
 * Test with listener.
 */
@Test
void testAnimatorListener() {
    final AtomicReference<Animation> played = new AtomicReference<>();
    final AtomicReference<AnimState> stated = new AtomicReference<>();
    final AtomicReference<Integer> framed = new AtomicReference<>();
    final AnimatorListener listener = new AnimatorListener() {

        @Override
        public void notifyAnimPlayed(Animation anim) {
            played.set(anim);
        }

        @Override
        public void notifyAnimState(AnimState state) {
            stated.set(state);
        }

        @Override
        public void notifyAnimFrame(int frame) {
            framed.set(Integer.valueOf(frame));
        }
    };
    final Animation animation = new Animation(Animation.DEFAULT_NAME, 1, 3, 0.25, true, false);
    final SpriteAnimated sprite = new SpriteAnimatedImpl(Graphics.createImageBuffer(64, 32), 16, 8);
    sprite.addListener(listener);
    assertNull(played.get());
    assertNull(stated.get());
    assertNull(framed.get());
    sprite.play(animation);
    assertEquals(animation, played.get());
    assertEquals(AnimState.PLAYING, stated.get());
    assertEquals(Integer.valueOf(1), framed.get());
    played.set(null);
    stated.set(null);
    framed.set(null);
    sprite.removeListener(listener);
    sprite.play(animation);
    sprite.update(1.0);
    assertNull(played.get());
    assertNull(stated.get());
    assertNull(framed.get());
}
Also used : AnimatorListener(com.b3dgs.lionengine.AnimatorListener) AnimState(com.b3dgs.lionengine.AnimState) Animation(com.b3dgs.lionengine.Animation) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Aggregations

Animation (com.b3dgs.lionengine.Animation)41 Test (org.junit.jupiter.api.Test)19 Test (org.junit.Test)13 Animator (com.b3dgs.lionengine.Animator)9 SpriteAnimated (com.b3dgs.lionengine.graphic.SpriteAnimated)6 HashMap (java.util.HashMap)5 Xml (com.b3dgs.lionengine.Xml)4 AnimatorModel (com.b3dgs.lionengine.AnimatorModel)3 Media (com.b3dgs.lionengine.Media)3 AnimatableModel (com.b3dgs.lionengine.game.feature.AnimatableModel)3 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)3 Collision (com.b3dgs.lionengine.game.feature.collidable.Collision)3 Collection (java.util.Collection)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 AnimState (com.b3dgs.lionengine.AnimState)2 AnimatorListener (com.b3dgs.lionengine.AnimatorListener)2 LionEngineException (com.b3dgs.lionengine.LionEngineException)2 AnimationConfig (com.b3dgs.lionengine.game.AnimationConfig)2 Configurer (com.b3dgs.lionengine.game.Configurer)2 Animatable (com.b3dgs.lionengine.game.feature.Animatable)2