Grape.Cacheable Class
Provides a cache feature for a resource: when a resource is loaded multiple times, the expensive operations are executed only once. The resource uses the loadResource method to tell what to do when the resource should be actually loaded. A typical usage is for tile maps, when multiple sprites are on the same image.
Constructor
Grape.Cacheable
()
Item Index
Methods
getEstimatedTime
()
Number
Returns the estimated time to load the resource. Can be overridden.
Returns:
The estimated time
getResourceKey
()
An abstract method which should return the same key when the resource is the same, it is used as cache key. A typical key is the url.
load
-
onFinish
-
onError
-
onProgress
Called when the resource is needed to load.
Parameters:
-
onFinish
Functionhave to be called when the resource is finished
-
onError
Functionhave to be called when an error occurs
-
onProgress
Functionmay be called when the progress changes (value in percent)
loadResource
-
onFinish
-
onError
-
onProgress
This method is called when we want to load the resource and it is not in the cache.
Parameters:
-
onFinish
FunctionShould be called when the resource is ready. The parameter is the loaded data.
-
onError
FunctionShould be called when an error occurs
-
onProgress
FunctionShould be called when the loading progress changes (0-100)
process
-
(*)
This method is called after load is called. If load is called multiple times, this method is not called more than once. It should initialize the resource with the loaded data.
Parameters:
-
(*)
Objectdata The loaded data (passed to the onFinish method in loadResource