So I was thinking there are a few ways to do it.
1) At the point where you cache them.
2) Everytime you create them to be used or in the sprite class or sprite manager that calls them.
3) 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| 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(); } 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; }
} |