So I was thinking there are a few ways to do it.
- At the point where you cache them.
- Everytime you create them to be used or in the sprite class or sprite manager that calls them.
- Or have some sort of auto search that looks for a frame seperator.
How do you typically do it?
I just created a resourcecache but seemed like I was missing some management.
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import javax.imageio.ImageIO;
public abstract class ResourceFileCache {
protected HashMap hmResources;
public ResourceFileCache (){
hmResources = new HashMap();
}
// should this include the frames and store as a class? which has dir, name, frames
protected void load (String directory, String name){
try {
Object resource = ImageIO.read(new File(directory + name));
hmResources.put(name, resource);
} catch (IOException e) {
System.err.println("Failed to load resource: "+directory+name);
}
}
protected Object get (String name) {
Object resource = hmResources.get(name);
if (resource == null)
System.err.println("Failed to find resource: "+name);
return resource;
}
}