Skip to content

Instantly share code, notes, and snippets.

@mrp1q7z
Created September 1, 2014 13:47
Show Gist options
  • Save mrp1q7z/0a3d774f199506fe0b5f to your computer and use it in GitHub Desktop.
Save mrp1q7z/0a3d774f199506fe0b5f to your computer and use it in GitHub Desktop.
libGDX sample
package name.taoka.ugeee.basicgraphics;
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 MyGdxGame extends ApplicationAdapter {
SpriteBatch batch;
private TextureAtlas textureAtlas;
private Animation animation;
private float elapsedTime = 0;
@Override
public void create() {
batch = new SpriteBatch();
textureAtlas = new TextureAtlas(Gdx.files.internal("spritesheet.atlas"));
animation = new Animation(1 / 15f, textureAtlas.getRegions());
}
@Override
public void render() {
// 黒(R=0,G=0,B=0)で初期化
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
elapsedTime += Gdx.graphics.getDeltaTime();
batch.draw(animation.getKeyFrame(elapsedTime, true), 0, 0);
batch.end();
}
@Override
public void dispose() {
batch.dispose();
textureAtlas.dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment