I made the following class to render GIF images:
/**
* Loads a GIF file, and renders its frames on an update()
*
* @author taylorshuler
*/
public class Animation2D {
private final GifDecoder decoder = new GifDecoder();
private final AWTLoader loader = new AWTLoader();
private final SimpleApplication app;
private int frameIndex;
private float frameDelay = decoder.getFrameCount() > 0 ? decoder.getDelay(frameIndex) : 0;
public Animation2D(SimpleApplication app, String path) {
this.app = app;
TextureKey key = new TextureKey(path, false);
AssetInfo info = app.getAssetManager().locateAsset(key);
try (InputStream stream = info.openStream()) {
decoder.read(stream);
} catch (IOException err) {
KnightRite.LOGGER.log(Level.SEVERE, "Count not find texture file!", err);
}
}
public void update(Picture pic, float tpf) {
frameDelay -= tpf;
if (frameDelay < 0) {
frameDelay = decoder.getDelay(frameIndex) / 1000F;
Texture2D tex = new Texture2D(loader.load(decoder.getFrame(frameIndex), true));
pic.setTexture(app.getAssetManager(), tex, true);
if (frameIndex < decoder.getFrameCount() - 1) {
++frameIndex;
} else {
frameIndex = 0;
}
}
}
}
I would like to render this and then my Nifty GUI stuff. How would I do so?