HTML and CSS Reference
In-Depth Information
AssetCache.create = // Constructor function
function (cacheParams) {
if (!cacheParams.onLoad) {
return null;
}
var assetCache = new AssetCache();
assetCache.maxCacheSize = cacheParams.size || 64;
assetCache.onLoad = cacheParams.onLoad;
assetCache.onDestroy = cacheParams.onDestroy;
assetCache.hitCounter = 0;
assetCache.cache = {};
assetCache.cacheArray = [];
return assetCache;
};
AssetCache.version = 2;
return AssetCache;
})();
/**
* Usage:
*
* A textureCache is created to store up to 100 textures in the cache.
* The onLoad and onDestroy functions give the game control
* of how the assets are created and destroy.
*
* In the render loop the texture is fetched from the cache.
* It will be rendered if it exists, otherwise will be requested.
*
* The render loop is unaware of how the texture is obtained, only that
* it will be requested as soon as possible.
*/
var textureCache = AssetCache.create({
size: 100,
onLoad: function loadTextureFn(key, params, loadedCallback) {
requestTexture(key, loadedCallback);
},
onDestroy: function destroyTextureFn(key, texture) {
if (texture) {
texture.destroy();
}
}
});
Search WWH ::




Custom Search