use of com.b3dgs.lionengine.Animation in project lionengine by b3dgs.
the class SpriteAnimatedTest method testUpdateLoopReverse.
/**
* Test update with loop and reverse.
*/
@Test
void testUpdateLoopReverse() {
final Animation animation = new Animation(Animation.DEFAULT_NAME, 1, 3, 1.0, true, true);
final SpriteAnimated sprite = new SpriteAnimatedImpl(Graphics.createImageBuffer(64, 32), 16, 8);
sprite.play(animation);
assertEquals(AnimState.PLAYING, sprite.getAnimState());
assertEquals(1, sprite.getFrame());
assertEquals(1, sprite.getFrameAnim());
sprite.update(1.0);
assertEquals(AnimState.PLAYING, sprite.getAnimState());
assertEquals(2, sprite.getFrame());
assertEquals(2, sprite.getFrameAnim());
sprite.update(1.0);
assertEquals(AnimState.PLAYING, sprite.getAnimState());
assertEquals(3, sprite.getFrame());
assertEquals(3, sprite.getFrameAnim());
sprite.update(1.0);
assertEquals(AnimState.REVERSING, sprite.getAnimState());
assertEquals(2, sprite.getFrame());
assertEquals(2, sprite.getFrameAnim());
sprite.update(1.0);
assertEquals(AnimState.PLAYING, sprite.getAnimState());
assertEquals(1, sprite.getFrame());
assertEquals(1, sprite.getFrameAnim());
sprite.update(1.0);
assertEquals(AnimState.PLAYING, sprite.getAnimState());
assertEquals(2, sprite.getFrame());
assertEquals(2, sprite.getFrameAnim());
sprite.update(1.0);
assertEquals(AnimState.PLAYING, sprite.getAnimState());
assertEquals(3, sprite.getFrame());
assertEquals(3, sprite.getFrameAnim());
sprite.update(1.0);
assertEquals(AnimState.REVERSING, sprite.getAnimState());
assertEquals(2, sprite.getFrame());
assertEquals(2, sprite.getFrameAnim());
}
use of com.b3dgs.lionengine.Animation in project lionengine by b3dgs.
the class SpriteAnimatedTest method testPlay.
/**
* Test play.
*/
@Test
void testPlay() {
final Animation animation = new Animation(Animation.DEFAULT_NAME, 1, 2, 1.5, false, false);
final SpriteAnimated sprite = new SpriteAnimatedImpl(Graphics.createImageBuffer(64, 32), 16, 8);
sprite.play(animation);
assertEquals(animation, sprite.getAnim());
assertEquals(AnimState.PLAYING, sprite.getAnimState());
assertEquals(2, sprite.getFrames());
assertEquals(1, sprite.getFrame());
assertEquals(1, sprite.getFrameAnim());
assertEquals(1.5, sprite.getAnimSpeed());
sprite.update(1.0);
assertEquals(AnimState.PLAYING, sprite.getAnimState());
assertEquals(2, sprite.getFrames());
assertEquals(2, sprite.getFrame());
assertEquals(2, sprite.getFrameAnim());
assertEquals(1.5, sprite.getAnimSpeed());
}
use of com.b3dgs.lionengine.Animation in project lionengine by b3dgs.
the class SpriteAnimatedTest method testUpdateLoopNoReverse.
/**
* Test update with loop but no reverse.
*/
@Test
void testUpdateLoopNoReverse() {
final Animation animation = new Animation(Animation.DEFAULT_NAME, 1, 3, 1.0, false, true);
final SpriteAnimated sprite = new SpriteAnimatedImpl(Graphics.createImageBuffer(64, 32), 16, 8);
sprite.play(animation);
assertEquals(AnimState.PLAYING, sprite.getAnimState());
assertEquals(1, sprite.getFrame());
assertEquals(1, sprite.getFrameAnim());
sprite.update(1.0);
assertEquals(AnimState.PLAYING, sprite.getAnimState());
assertEquals(2, sprite.getFrame());
assertEquals(2, sprite.getFrameAnim());
sprite.update(1.0);
assertEquals(AnimState.PLAYING, sprite.getAnimState());
assertEquals(3, sprite.getFrame());
assertEquals(3, sprite.getFrameAnim());
sprite.update(1.0);
assertEquals(AnimState.PLAYING, sprite.getAnimState());
assertEquals(1, sprite.getFrame());
assertEquals(1, sprite.getFrameAnim());
sprite.update(1.0);
assertEquals(AnimState.PLAYING, sprite.getAnimState());
assertEquals(2, sprite.getFrame());
assertEquals(2, sprite.getFrameAnim());
}
use of com.b3dgs.lionengine.Animation in project lionengine by b3dgs.
the class SpriteAnimatedTest method testSetSpeedNegative.
/**
* Test negative speed.
*/
@Test
void testSetSpeedNegative() {
final Animation animation = new Animation(Animation.DEFAULT_NAME, 1, 3, 1.0, false, false);
final SpriteAnimated sprite = new SpriteAnimatedImpl(Graphics.createImageBuffer(64, 32), 16, 8);
sprite.play(animation);
sprite.setAnimSpeed(-1.0);
sprite.setFrame(3);
sprite.update(1.0);
assertEquals(AnimState.PLAYING, sprite.getAnimState());
assertEquals(2, sprite.getFrame());
assertEquals(2, sprite.getFrameAnim());
}
use of com.b3dgs.lionengine.Animation in project lionengine by b3dgs.
the class AnimatableModelTest method testReset.
/**
* Test the reset case.
*/
@Test
void testReset() {
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);
animatable.play(animation);
testAnimatorState(animatable, first, first, AnimState.PLAYING);
animatable.reset();
testAnimatorState(animatable, 1, 1, AnimState.STOPPED);
}
Aggregations