Skip to content

Instantly share code, notes, and snippets.

@ImDevinC
Created December 4, 2014 20:21
Show Gist options
  • Save ImDevinC/e50c38d8e9d5bd96025f to your computer and use it in GitHub Desktop.
Save ImDevinC/e50c38d8e9d5bd96025f to your computer and use it in GitHub Desktop.
LibGdx Sprite
public class GameRenderer {
private OrthographicCamera camera;
private SpriteBatch batch;
private SoundSprite sound;
private int score;
public GameRenderer() {
camera = new OrthographicCamera();
camera.setToOrtho(true, 800, 600);
batch = new SpriteBatch();
batch.setProjectionMatrix(camera.combined);
sound = new SoundSprite("soundOn");
sound.setPosition((Gdx.graphics.getWidth() / 2), (Gdx.graphics.getHeight() / 2));
score = 0;
}
public void render() {
Gdx.gl.glClearColor(7/255.0f, 99/255.0f, 36/255.0f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
sound.draw(batch); // Draws nothing on screen
AssetLoader.bitmapFont.draw(batch, "Score: " + String.valueOf(score), 0, 0); // Draws proper text on screen
batch.end();
}
}
public class SoundSprite extends Sprite {
public SoundSprite(String atlasId) {
setRegion(AssetLoader.getVolumeTextureRegion(atlasId)); // AssetLoader.getVolumeTextureRegion returns a texture region from a TextureAtlas
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment