Right now, I have an
AssetLoader interface, which has one implementation per platform. There can only be one instance of it, because it has some state (e.g. the path to the APK on Android).
It has two methods (the game doesn't have sound):
Pixmap loadImage(String path)
Pixmap loadText(String text, String fontFamily, int fontSize)
While that works well enough in practice, I feel this is bad design. In particular, I have two issues with it:
- I have to duplicate image and font loading. It's not exactly the same code, because there are different methods used for loading from the file system and loading from a ZIP file, but I could certainly just load a font or an image into memory and return that.
loadTextdoes a bit much at the moment: It loads a font from the disk, renders each glyph of the text onto a pixmap and returns that. More unnecessary code duplication.
What do you think, is this as bad as I think it is? How would you address it?
I don't insist on having a single
AssetLoader with one implementation per platform, so please don't hold your suggestion back because it would get rid of that. In fact, I'm not perfectly happy with the beast, but can't think of a nicer approach.