Skip to content

Instantly share code, notes, and snippets.

@mrp1q7z
Last active August 29, 2015 14:06
Show Gist options
  • Save mrp1q7z/808546ce97929fff9e8e to your computer and use it in GitHub Desktop.
Save mrp1q7z/808546ce97929fff9e8e 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.InputProcessor;
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;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
public class MyGdxGame extends ApplicationAdapter implements InputProcessor {
SpriteBatch batch;
private TextureAtlas textureAtlas;
private float elapsedTime = 0;
private Animation rotateUpAnimation;
private Animation rotateDownAnimation;
@Override
public void create() {
batch = new SpriteBatch();
textureAtlas = new TextureAtlas(Gdx.files.internal("spritesheet.atlas"));
TextureRegion[] rotateUpFrames = new TextureRegion[10];
// Rotate Up Animation
// Create an array of TextureRegions
rotateUpFrames[0] = (textureAtlas.findRegion("jet01"));
rotateUpFrames[1] = (textureAtlas.findRegion("jet02"));
rotateUpFrames[2] = (textureAtlas.findRegion("jet03"));
rotateUpFrames[3] = (textureAtlas.findRegion("jet04"));
rotateUpFrames[4] = (textureAtlas.findRegion("jet05"));
rotateUpFrames[5] = (textureAtlas.findRegion("jet06"));
rotateUpFrames[6] = (textureAtlas.findRegion("jet07"));
rotateUpFrames[7] = (textureAtlas.findRegion("jet08"));
rotateUpFrames[8] = (textureAtlas.findRegion("jet09"));
rotateUpFrames[9] = (textureAtlas.findRegion("jet10"));
rotateUpAnimation = new Animation(0.1f, rotateUpFrames);
// Rotate Down Animation
// Or you can just pass in all of the regions to the Animation
// constructor
rotateDownAnimation = new Animation(0.1f,
(textureAtlas.findRegion("jet11")),
(textureAtlas.findRegion("jet12")),
(textureAtlas.findRegion("jet13")),
(textureAtlas.findRegion("jet14")),
(textureAtlas.findRegion("jet15")),
(textureAtlas.findRegion("jet16")),
(textureAtlas.findRegion("jet17")),
(textureAtlas.findRegion("jet18")),
(textureAtlas.findRegion("jet19")),
(textureAtlas.findRegion("jet01")));
Gdx.input.setInputProcessor(this);
}
@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(rotateUpAnimation.getKeyFrame(elapsedTime, true), 0, 0);
batch.draw(rotateDownAnimation.getKeyFrame(elapsedTime, true), 200, 0);
batch.end();
}
@Override
public void dispose() {
batch.dispose();
textureAtlas.dispose();
}
@Override
public boolean keyDown(int keycode) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean keyUp(int keycode) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean keyTyped(char character) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean scrolled(int amount) {
// TODO Auto-generated method stub
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment