Search in sources :

Example 1 with AnimatorModel

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

the class AnimatableModelTest method testManipulation.

/**
 * Test the manipulations.
 */
@Test
void testManipulation() {
    final int first = 2;
    final int last = 5;
    final double speed = 2.0;
    final Animation animation = new Animation(Animation.DEFAULT_NAME, first, last, speed, false, false);
    final Animatable animatable = new AnimatableModel(services, setup, new AnimatorModel());
    testAnimatorState(animatable, Animation.MINIMUM_FRAME, Animation.MINIMUM_FRAME, AnimState.STOPPED);
    animatable.play(animation);
    testAnimatorState(animatable, first, first, AnimState.PLAYING);
    animatable.setAnimSpeed(speed - 1.0);
    animatable.update(1.0);
    testAnimatorState(animatable, first, first + 1, AnimState.PLAYING);
    animatable.update(1.0);
    animatable.setFrame(1);
    testAnimatorState(animatable, first, 1, AnimState.PLAYING);
    animatable.stop();
    testAnimatorState(animatable, first, 1, AnimState.STOPPED);
}
Also used : Animation(com.b3dgs.lionengine.Animation) AnimatorModel(com.b3dgs.lionengine.AnimatorModel) Test(org.junit.jupiter.api.Test)

Example 2 with AnimatorModel

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

the class UtilAttackable method prepare.

/**
 * Create the featurable.
 *
 * @param featurable The featurable to prepare.
 * @param services The services reference.
 * @param setup The setup reference.
 */
public static void prepare(Featurable featurable, Services services, Setup setup) {
    final Animator animator = new AnimatorModel();
    animator.play(new Animation("test", 1, 1, 1.0, false, false));
    featurable.addFeature(new AnimatableModel(services, setup, animator));
    featurable.addFeature(new TransformableModel(services, setup));
}
Also used : Animator(com.b3dgs.lionengine.Animator) AnimatableModel(com.b3dgs.lionengine.game.feature.AnimatableModel) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Animation(com.b3dgs.lionengine.Animation) AnimatorModel(com.b3dgs.lionengine.AnimatorModel)

Example 3 with AnimatorModel

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

Animation (com.b3dgs.lionengine.Animation)3 AnimatorModel (com.b3dgs.lionengine.AnimatorModel)3 Test (org.junit.jupiter.api.Test)2 AnimState (com.b3dgs.lionengine.AnimState)1 Animator (com.b3dgs.lionengine.Animator)1 AnimatorListener (com.b3dgs.lionengine.AnimatorListener)1 AnimatableModel (com.b3dgs.lionengine.game.feature.AnimatableModel)1 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1