Skip to content

Instantly share code, notes, and snippets.

@StrongJoshua
Created September 26, 2015 20:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StrongJoshua/13ff8f1b9bfef304be98 to your computer and use it in GitHub Desktop.
Save StrongJoshua/13ff8f1b9bfef304be98 to your computer and use it in GitHub Desktop.
Resource management using LibGdx
class TextureManager implements Disposable {
private ObjectMap<String, Texture> textures;
public TextureManager() {
textures = new ObjectMap<String, Texture>();
}
public Texture getTexture(String path) {
Texture t = textures.get(path);
if(t == null) {
t = new Texture(Gdx.files.internal(path));
textures.put(path, t);
}
return t;
}
public void clearAll() {
Entries<String, Texture> e = new Entries<String, Texture>(textures);
while(e.hasNext()) {
e.next().value.dispose();
}
textures.clear();
}
@Override
public void dispose() {
clearAll();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment