Working on a simple video game in JavaScript / HTML5, and I had a thought to collect all of my resources within one class...currently they're spread all over the place.
So, for an example, currently I have something along the lines of
function c_enemy_sprites() {
this.image = new Image();
this.image.src = "res/enemies.png";
..
..
}
function c_tilemap() {
this.image = new Image();
this.image.src = "res/tilemap.png";
..
..
}
I'd like to commonize this into a single class, as so
function c_resource() {
this.enemies.image = new Image();
this.enemies.image.src = "res/enemies.png";
this.tilemap.image = new Image();
this.tilemap.image.src = "res/tilemap.png";
..
..
}
However, I don't think this is the proper approach. The program crashes spectacularly when I try the second implementation. Is there a good way to simplify my resource loading?