Search in sources :

Example 1 with AnimState

use of com.b3dgs.lionengine.AnimState 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)

Example 2 with AnimState

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

the class AnimatableModelTest method testListener.

/**
 * Test with listener.
 */
@Test
void testListener() {
    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 Animatable animatable = new AnimatableModel(services, setup, new AnimatorModel());
    animatable.addListener(listener);
    assertNull(played.get());
    assertNull(stated.get());
    assertNull(framed.get());
    animatable.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);
    animatable.removeListener(listener);
    animatable.play(animation);
    animatable.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) AnimatorModel(com.b3dgs.lionengine.AnimatorModel) Test(org.junit.jupiter.api.Test)

Aggregations

AnimState (com.b3dgs.lionengine.AnimState)2 Animation (com.b3dgs.lionengine.Animation)2 AnimatorListener (com.b3dgs.lionengine.AnimatorListener)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Test (org.junit.jupiter.api.Test)2 AnimatorModel (com.b3dgs.lionengine.AnimatorModel)1