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);
}
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));
}
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());
}
Aggregations