use of com.b3dgs.lionengine.Animation 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.Animation in project lionengine by b3dgs.
the class AnimatableModelTest method testPlay.
/**
* Test the play case.
*/
@Test
void testPlay() {
final int first = 2;
final int last = 4;
final Animation animation = new Animation(Animation.DEFAULT_NAME, first, last, 1.0, false, false);
final Animatable animatable = new AnimatableModel(services, setup);
testAnimatorState(animatable, Animation.MINIMUM_FRAME, Animation.MINIMUM_FRAME, AnimState.STOPPED);
assertEquals(1, animatable.getFrames());
animatable.play(animation);
assertEquals(animation, animatable.getAnim());
testAnimatorState(animatable, first, first, AnimState.PLAYING);
assertFalse(animatable.is(AnimState.FINISHED));
assertEquals(last - first + 1, animatable.getFrames());
animatable.update(1.0);
testAnimatorState(animatable, first, first + 1, AnimState.PLAYING);
animatable.update(1.0);
testAnimatorState(animatable, first, last, AnimState.PLAYING);
animatable.update(1.0);
testAnimatorState(animatable, first, last, AnimState.FINISHED);
animatable.stop();
testAnimatorState(animatable, first, last, AnimState.STOPPED);
}
use of com.b3dgs.lionengine.Animation in project lionengine by b3dgs.
the class AnimationConfigTest method testExportsImports.
/**
* Test exports imports.
*/
@Test
void testExportsImports() {
final Xml root = new Xml("test");
final Animation animation1 = new Animation("anim1", 1, 2, 3.0, false, true);
final Animation animation2 = new Animation("anim2", 4, 5, 6.0, true, false);
AnimationConfig.exports(root, animation1);
AnimationConfig.exports(root, animation2);
final Media media = Medias.create("animations.xml");
root.save(media);
final AnimationConfig imported = AnimationConfig.imports(new Setup(media));
assertEquals(animation1, imported.getAnimation("anim1"));
assertEquals(animation2, imported.getAnimation("anim2"));
assertTrue(imported.getAnimations().containsAll(Arrays.asList(animation1, animation2)));
assertFalse(imported.hasAnimation("anim"));
assertTrue(imported.hasAnimation("anim1"));
assertTrue(imported.hasAnimation("anim2"));
assertTrue(media.getFile().delete());
}
use of com.b3dgs.lionengine.Animation in project lionengine by b3dgs.
the class RasterableModelTest method testModel.
/**
* Test the model.
*/
@Test
void testModel() {
services.add(new ViewerMock());
final SetupSurfaceRastered setup = new SetupSurfaceRastered(Medias.create(OBJECT_XML));
final Featurable featurable = new FeaturableModel(services, setup);
final Transformable transformable = featurable.addFeatureAndGet(new TransformableModel(services, setup));
final Animatable animatable = featurable.addFeatureAndGet(new AnimatableModel(services, setup));
featurable.addFeature(new MirrorableModel(services, setup));
final Rasterable rasterable = new RasterableModel(services, setup);
rasterable.setFrameOffsets(1, 2);
rasterable.prepare(featurable);
rasterable.setOrigin(Origin.TOP_LEFT);
rasterable.update(1.0);
rasterable.setEnabled(false);
rasterable.update(1.0);
rasterable.render(g);
assertTrue(rasterable.isVisible());
rasterable.setVisibility(false);
rasterable.update(1.0);
rasterable.render(g);
assertFalse(rasterable.isVisible());
assertEquals(1, rasterable.getRasterIndex(0));
assertEquals(RasterImage.MAX_RASTERS, rasterable.getRasterIndex(240));
assertNotNull(rasterable.getRasterAnim(0));
transformable.teleportY(-100);
rasterable.update(1.0);
assertEquals(1, rasterable.getRasterIndex(0));
assertEquals(RasterImage.MAX_RASTERS, rasterable.getRasterIndex(240));
assertNotNull(rasterable.getRasterAnim(0));
animatable.play(new Animation("default", 1, 5, 1.0, false, false));
animatable.update(1.0);
rasterable.update(1.0);
assertEquals(1, rasterable.getRasterAnim(0).getFrame());
rasterable.setAnimOffset(1);
rasterable.update(1.0);
assertEquals(1, rasterable.getRasterAnim(0).getFrame());
}
use of com.b3dgs.lionengine.Animation in project lionengine by b3dgs.
the class StateHandlerTest method testWithConfig.
/**
* Test state with configuration.
*/
@Test
void testWithConfig() {
Medias.setLoadFromJar(StateHandlerTest.class);
try {
final Setup setup = new Setup(Medias.create("Object.xml"));
final Featurable featurable = new FeaturableModel(services, setup);
final StateHandler handler;
handler = featurable.addFeatureAndGet(new StateHandler(services, setup));
handler.prepare(featurable);
handler.changeState(StateIdle.class);
handler.postUpdate();
assertEquals(new Animation(StateIdle.class.getSimpleName(), 1, 1, 0.125, false, false), StateIdle.animation);
assertNull(StateWalk.animation);
assertTrue(handler.isState(StateIdle.class));
handler.update(1.0);
assertNull(StateWalk.animation);
handler.postUpdate();
assertEquals(new Animation(StateWalk.class.getSimpleName(), 2, 2, 0.125, false, false), StateWalk.animation);
assertTrue(handler.isState(StateWalk.class));
handler.update(1.0);
handler.postUpdate();
assertTrue(handler.isState(StateIdle.class));
} finally {
Medias.setLoadFromJar(null);
}
}
Aggregations