Director

Caching Resources

A director object is able to manage resources, concretely images and sounds.

Images

Caching images is a pretty straightforward operation. The methods to manage images are:

setImagesCache( obj ). This method substitutes director's previous images cache. The obj parameter is an object of the form:

                            [
                                { id: string, image: image },
                                ...
                            ]
                        
This method should be used in conjunction with an instance of CAAT.ImagePreloader in the following way:
                            new CAAT.ImagePreloader().loadImages(
                                [
                                    {id:'fish',     url:'res/img/anim1.png'},
                                    {id:'fish2',    url:'res/img/anim2.png'},
                                    {id:'fish3',    url:'res/img/anim3.png'},
                                    ...
                                ],

                                function( counter, images ) {

                                    if ( counter==images.length ) {
                                        director.setImagesCache(images);
                                    }
                                }
                        

Other image management methods are:

addImage : function( id, image, noUpdateGL ).
This method adds a new image to the cache. If the id parameter corresponds to an already existent image, the image will be modified with the new one. The parameter noUpdateGL if set to false, will cause the webGL texture pages to be recreated. If rendering with webGL, this operation is error prone, since the already created CAAT.SpriteImage instances could reference wrongly its textures.

deleteImage : function( id, noUpdateGL ).
This method removes an image from the cache. As in the previous method, be aware of calling this method with webGL enabled renderers.

Sound

CAAT has a built in AudioManager which is able to play eight simultaneous sounds. Each concurrent sound is called a channel, and allows to play concurrently the same sound, loop (and fix FF<5 loop problems), etc. When there are arlready 8 playing channels, no more sounds will be played until any channel gets available.

The method to manage the sounds are:

addAudio : function(id, url).
This method adds a reference to an Audio or HTMLAudioElement object.

audioPlay : function(id).
Plays a sound, occupying a channel which will be freed upon audio play end.

audioLoop : function(id).
Loops a sound, occupying a channel which will be freed upon audio play end.