Skip to content

Instantly share code, notes, and snippets.

@dzt
Created March 1, 2015 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dzt/005e70cd07752d900e69 to your computer and use it in GitHub Desktop.
Save dzt/005e70cd07752d900e69 to your computer and use it in GitHub Desktop.
GDX Animation Example
package com.petersoboyejo.firstgdxgame;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
public class Game extends ApplicationAdapter {
private SpriteBatch batch;
private TextureAtlas bikerAtlas;
private Animation animation;
private float timePassed = 0;
@Override
public void create() {
batch = new SpriteBatch();
bikerAtlas = new TextureAtlas(Gdx.files.internal("file.atlas"));
animation = new Animation(30f / 1, bikerAtlas.getRegions());
}
@Override
public void dispose() {
batch.dispose();
bikerAtlas.dispose();
}
@Override
public void render() {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
// Time that passed since the animation started
// "true" tells your animations to loop
timePassed += Gdx.graphics.getDeltaTime();
batch.draw(animation.getKeyFrame(timePassed, true), 300, 500);
batch.end();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment