1     /**
2         A database for the external resources used by the game
3         @author <a href="mailto:matthewcasperson@gmail.com">Matthew Casperson</a>
4         @class
5     */
6     function ResourceManager()
7 {
8 /** An array of the names of the images supplied to the startupResourceManager 9 function. Since the images are referenced by creating new properties 10 of the ResourceManager class this collection allows a developer to 11 know which of the ResourceManager properties are images, and (by 12 elimination) those that are not 13 @type Array 14 */ 15 this.imageProperties = null;
16 17 /** 18 Initialises this object 19 @param images An array of objects with the name and src properties 20 @return A reference to the initialised object 21 */ 22 this.startupResourceManager = function(/**Array*/ images)
23 {
24 // set the global variable 25 g_ResourceManager = this;
26 27 // initialize internal state. 28 this.imageProperties = new Array();
29 30 // for each image, call preload() 31 for ( var i = 0; i < images.length; i++ )
32 {
33 // create new Image object and add to array 34 var thisImage = new Image;
35 this[images[i].name] = thisImage;
36 this.imageProperties.push(images[i].name);
37 38 // assign the .src property of the Image object 39 thisImage.src = images[i].src;
40 }
41 42 return this;
43 }
44 }
Top