use of com.gemserk.animation4j.gdx.Animation in project commons-gdx by gemserk.
the class AnimationFromTextureAtlasResourceBuilder method build.
@Override
public Animation build() {
TextureAtlas textureAtlas = resourceManager.getResourceValue(textureAtlasId);
if (sprites == null) {
try {
sprites = textureAtlas.createSprites(prefix);
} catch (GdxRuntimeException e) {
throw new RuntimeException("Failed to create animation from texture atlas " + textureAtlasId, e);
}
}
if (endFrame == -1)
endFrame = sprites.size - 1;
if (startFrame == -1)
startFrame = 0;
Sprite[] frames = new Sprite[endFrame - startFrame + 1];
int frameNumber = startFrame;
for (int i = 0; i < frames.length; i++) {
Sprite sprite = sprites.get(frameNumber);
if (sprite instanceof AtlasSprite)
frames[i] = new AtlasSprite(((AtlasSprite) sprite).getAtlasRegion());
else
frames[i] = new Sprite(sprite);
frameTransformation.transform(frames[i]);
frameNumber++;
}
int framesCount = frames.length;
float[] newTimes = new float[framesCount - 1];
int lastTime = time;
for (int i = 0; i < framesCount - 1; i++) {
if (i < times.length) {
newTimes[i] = ((float) times[i]) * 0.001f;
lastTime = times[i];
} else
newTimes[i] = ((float) lastTime) * 0.001f;
}
FrameAnimationImpl frameAnimation = new FrameAnimationImpl(0.001f * (float) time, newTimes);
frameAnimation.setLoop(loop);
return new Animation(frames, frameAnimation);
}
use of com.gemserk.animation4j.gdx.Animation in project commons-gdx by gemserk.
the class AnimationMonitorTest method shouldNotBeShownWhenStarted.
@Test
public void shouldNotBeShownWhenStarted() {
Animation animation = new Animation(new Sprite[] {}, new FrameAnimationImpl(true, 50f, 25f, 30f));
AnimationFrameMonitor animationMonitor = new AnimationFrameMonitor(animation, 50f);
animation.update(1f);
animationMonitor.update();
assertFalse(animationMonitor.isTriggered());
}
use of com.gemserk.animation4j.gdx.Animation in project commons-gdx by gemserk.
the class AnimationMonitorTest method shouldNotTriggerAgainOnDifferentAnimationIterationButUpdatedTwice.
@Test
public void shouldNotTriggerAgainOnDifferentAnimationIterationButUpdatedTwice() {
Animation animation = new Animation(new Sprite[] {}, new FrameAnimationImpl(true, 50f, 25f, 30f));
AnimationFrameMonitor animationMonitor = new AnimationFrameMonitor(animation, 50f);
animation.update(51f);
animationMonitor.update();
animationMonitor.update();
animation.update(25f + 30f + 50f);
animationMonitor.update();
animationMonitor.update();
assertFalse(animationMonitor.isTriggered());
}
use of com.gemserk.animation4j.gdx.Animation in project commons-gdx by gemserk.
the class AnimationMonitorTest method shouldTriggerAgainOnDifferentAnimationIteration.
@Test
public void shouldTriggerAgainOnDifferentAnimationIteration() {
Animation animation = new Animation(new Sprite[] {}, new FrameAnimationImpl(true, 50f, 25f, 30f));
AnimationFrameMonitor animationMonitor = new AnimationFrameMonitor(animation, 50f);
animation.update(51f);
animationMonitor.update();
animationMonitor.update();
animation.update(25f + 30f + 50f);
animationMonitor.update();
assertTrue(animationMonitor.isTriggered());
}
use of com.gemserk.animation4j.gdx.Animation in project commons-gdx by gemserk.
the class AnimationMonitorTest method shouldTriggerIfDirecltyChangedIteration.
@Test
public void shouldTriggerIfDirecltyChangedIteration() {
Animation animation = new Animation(new Sprite[] {}, new FrameAnimationImpl(true, 50f, 25f, 30f));
AnimationFrameMonitor animationMonitor = new AnimationFrameMonitor(animation, 50f);
animation.update(50f + 25f + 31f);
animationMonitor.update();
assertTrue(animationMonitor.isTriggered());
}
Aggregations