Created
January 11, 2017 09:10
-
-
Save reime005/87e1ed30548be31a632292a604f397ef to your computer and use it in GitHub Desktop.
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
package com.hmack.hammerize.utils; | |
import com.badlogic.gdx.assets.AssetManager; | |
import com.badlogic.gdx.graphics.g2d.Animation; | |
import com.badlogic.gdx.graphics.g2d.TextureAtlas; | |
import com.badlogic.gdx.graphics.g2d.TextureRegion; | |
import java.util.HashMap; | |
/** | |
* Created by marius on 26-Jan-16. | |
*/ | |
public class AssetsManager { | |
private static AssetsManager instance = new AssetsManager(); | |
private HashMap<String, TextureRegion> textureMap = new HashMap<String, TextureRegion>(); | |
private HashMap<String, Animation> animationMap = new HashMap<String, Animation>(); | |
private TextureAtlas textureAtlas; | |
private AssetManager manager; | |
private AssetsManager() { | |
if (manager == null) { | |
manager = new AssetManager(); | |
} | |
} | |
public static AssetsManager getInstance() { | |
return instance; | |
} | |
private static Animation createAnimation(TextureAtlas textureAtlas, String[] regionNames) { | |
TextureRegion[] frames = new TextureRegion[regionNames.length]; | |
for (int i = 0; i < regionNames.length; i++) { | |
String path = regionNames[i]; | |
frames[i] = textureAtlas.findRegion(path); | |
} | |
return new Animation(0.1f, frames); | |
} | |
public void loadAssets() { | |
manager = new AssetManager(); | |
manager.load("sprites.atlas", TextureAtlas.class); | |
} | |
private void getTexturesAndAnimations() { | |
textureAtlas = manager.get(Constants.SPRITES_ATLAS_PATH, TextureAtlas.class); | |
String[] firstAnimation = {"FILENAME_WITHOUT_ENDING_0", "FILENAME_WITHOUT_ENDING_1"}; | |
animationMap.put("KEY_RELATED_TO_FIRST_ANIMATION", createAnimation(textureAtlas, firstAnimation)); | |
} | |
public TextureAtlas getTextureAtlas() { | |
return textureAtlas; | |
} | |
public Animation getAnimation(String key) { | |
return animationMap.get(key); | |
} | |
public TextureRegion getTextureRegion(String key) { | |
return textureMap.get(key); | |
} | |
public AssetManager getManager() { | |
return manager; | |
} | |
public void dispose() { | |
textureMap.clear(); | |
animationMap.clear(); | |
textureAtlas.dispose(); | |
manager.dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment