Search in sources :

Example 1 with Animation

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

the class AnimationConfig method imports.

/**
 * Create the animation data from configurer.
 *
 * @param root The root reference (must not be <code>null</code>).
 * @return The animations configuration instance.
 * @throws LionEngineException If unable to read data.
 */
public static AnimationConfig imports(Xml root) {
    Check.notNull(root);
    final Map<String, Animation> animations = new HashMap<>(0);
    for (final Xml node : root.getChildren(ANIMATION)) {
        final String anim = node.readString(ANIMATION_NAME);
        final Animation animation = createAnimation(node);
        animations.put(anim, animation);
    }
    return new AnimationConfig(animations);
}
Also used : HashMap(java.util.HashMap) Xml(com.b3dgs.lionengine.io.Xml) Animation(com.b3dgs.lionengine.Animation)

Example 2 with Animation

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

the class AnimatorTest method testUpdateLoopNoReverse.

/**
 * Test update with loop but no reverse.
 */
@Test
public void testUpdateLoopNoReverse() {
    final Animation animation = new Animation(Animation.DEFAULT_NAME, 1, 3, 1.0, false, true);
    final Animator animator = new AnimatorImpl();
    animator.play(animation);
    Assert.assertEquals(AnimState.PLAYING, animator.getAnimState());
    Assert.assertEquals(1, animator.getFrame());
    Assert.assertEquals(1, animator.getFrameAnim());
    animator.update(1.0);
    Assert.assertEquals(AnimState.PLAYING, animator.getAnimState());
    Assert.assertEquals(2, animator.getFrame());
    Assert.assertEquals(2, animator.getFrameAnim());
    animator.update(1.0);
    Assert.assertEquals(AnimState.PLAYING, animator.getAnimState());
    Assert.assertEquals(3, animator.getFrame());
    Assert.assertEquals(3, animator.getFrameAnim());
    animator.update(1.0);
    Assert.assertEquals(AnimState.PLAYING, animator.getAnimState());
    Assert.assertEquals(1, animator.getFrame());
    Assert.assertEquals(1, animator.getFrameAnim());
    animator.update(1.0);
    Assert.assertEquals(AnimState.PLAYING, animator.getAnimState());
    Assert.assertEquals(2, animator.getFrame());
    Assert.assertEquals(2, animator.getFrameAnim());
}
Also used : Animator(com.b3dgs.lionengine.Animator) Animation(com.b3dgs.lionengine.Animation) Test(org.junit.Test)

Example 3 with Animation

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

the class AnimatorTest method testSetSpeed.

/**
 * Test set speed.
 */
@Test
public void testSetSpeed() {
    final Animation animation = new Animation(Animation.DEFAULT_NAME, 1, 3, 1.0, false, false);
    final Animator animator = new AnimatorImpl();
    animator.play(animation);
    animator.setAnimSpeed(2.0);
    animator.update(1.0);
    Assert.assertEquals(AnimState.PLAYING, animator.getAnimState());
    Assert.assertEquals(3, animator.getFrame());
    Assert.assertEquals(3, animator.getFrameAnim());
}
Also used : Animator(com.b3dgs.lionengine.Animator) Animation(com.b3dgs.lionengine.Animation) Test(org.junit.Test)

Example 4 with Animation

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

the class AnimatorTest method testUpdateNoLoopNoReverse.

/**
 * Test update without loop nor reverse.
 */
@Test
public void testUpdateNoLoopNoReverse() {
    final Animation animation = new Animation(Animation.DEFAULT_NAME, 1, 2, 1.0, false, false);
    final Animator animator = new AnimatorImpl();
    animator.play(animation);
    Assert.assertEquals(AnimState.PLAYING, animator.getAnimState());
    Assert.assertEquals(1, animator.getFrame());
    Assert.assertEquals(1, animator.getFrameAnim());
    animator.update(1.0);
    Assert.assertEquals(AnimState.PLAYING, animator.getAnimState());
    Assert.assertEquals(2, animator.getFrame());
    Assert.assertEquals(2, animator.getFrameAnim());
    animator.update(1.0);
    Assert.assertEquals(AnimState.FINISHED, animator.getAnimState());
    Assert.assertEquals(2, animator.getFrame());
    Assert.assertEquals(2, animator.getFrameAnim());
    animator.update(1.0);
    Assert.assertEquals(AnimState.FINISHED, animator.getAnimState());
    Assert.assertEquals(2, animator.getFrame());
    Assert.assertEquals(2, animator.getFrameAnim());
}
Also used : Animator(com.b3dgs.lionengine.Animator) Animation(com.b3dgs.lionengine.Animation) Test(org.junit.Test)

Example 5 with Animation

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

the class SpriteAnimatedTest method testPlay.

/**
 * Test play.
 */
@Test
public void testPlay() {
    final Animation animation = new Animation(Animation.DEFAULT_NAME, 1, 2, 3.0, false, 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());
}
Also used : SpriteAnimated(com.b3dgs.lionengine.graphic.SpriteAnimated) Animation(com.b3dgs.lionengine.Animation) Test(org.junit.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