Skip to content

Instantly share code, notes, and snippets.

@mrp1q7z
Created August 31, 2014 04:15
Show Gist options
  • Save mrp1q7z/b7d006a38953b4326597 to your computer and use it in GitHub Desktop.
Save mrp1q7z/b7d006a38953b4326597 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.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
import com.badlogic.gdx.utils.Timer;
import com.badlogic.gdx.utils.Timer.Task;
public class MyGdxGame extends ApplicationAdapter {
SpriteBatch batch;
private Sprite sprite;
private TextureAtlas textureAtlas;
private int currentFrame = 1;
private String currentAtlasKey = new String("jet01");
@Override
public void create() {
batch = new SpriteBatch();
textureAtlas = new TextureAtlas(Gdx.files.internal("spritesheet.atlas"));
AtlasRegion region = textureAtlas.findRegion("jet01");
sprite = new Sprite(region);
sprite.setPosition(120, 100);
sprite.scale(2.5f);
Timer.schedule(new Task() {
@Override
public void run() {
currentFrame++;
if (currentFrame > 20) {
currentFrame = 1;
}
// 注意!String.fromat() はhtml(GWT)プロジェクトでは動きません
currentAtlasKey = String.format("jet%02d", currentFrame);
sprite.setRegion(textureAtlas.findRegion(currentAtlasKey));
}
}, 0, 1 / 30.0f);
}
@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();
sprite.draw(batch);
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