Hi,
I got a design issue with my SpriteCache class.
It has a map to store Sprites. Sprites is the top object where all my sprites are extended from.
private HashMap<String, Sprite> spriteCache;
and my method to retrieve or when none there add the sprite to the spriteCache:
public Sprite getSprite(String name) {
if (spriteCache.containsKey(name)) {
return spriteCache.get(name);
} else {
logger.fine(name + " " + ERR_NOT_FOUND + " in spritesCache Making new one");
Sprite sprite = new Sprite(resources.getAnim(name), new Pt(0,0));
spriteCache.put(name, sprite);
return sprite;
}
}
When I call this Function to create a Cursor Sprite for example I get a Sprite and a classCast exception
Sprite curs = spriteCache.getSprite(“Cursor”);
Cursor cursor = (Cursor) curs;
What is the best way to work around this problem?
Should I add Specific Sprites like Cursor to the cache before calling spriteCache.get
Should I insert a parameter of the sprite to be created?
something like spriteCache.getSprite(“Cursor”,curs.class)
This is my design:
http://www.kwbbz.be/Downloads/Main.jpg