Created
September 26, 2015 20:02
-
-
Save StrongJoshua/13ff8f1b9bfef304be98 to your computer and use it in GitHub Desktop.
Resource management using LibGdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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