Grape.ResourceCollection Class
Represents a collection of resources. You can add, get different kind of resources (nested collections are allowed) and load resources at once.
Constructor
Grape.ResourceCollection
-
opts
Parameters:
-
optsObjectInitial properties
Methods
add
-
[name] -
Resource
Adds a new resource to the collection.
Parameters:
-
[name]String optionalThe unique name of the resource
-
ResourceGrape.Resource
audio
-
name -
opts -
url1 -
url2 -
url3
Creates an Audio resource and adds to the collection. Check Grape.Audio for more information.
Parameters:
-
nameStringKey
-
optsObjectAudio options
-
url1StringAudio URL
-
url2StringAudio URL fallback if url1 extension is not supported
-
url3StringAudio URL fallback if url2 extension is not supported
Returns:
The Audio resource
get
-
name
Get a previously added resource by name.
Parameters:
-
nameStringName
Returns:
the resource
getEstimatedTime
()
Number
Returns the sum of the estimated time of all resource.
Returns:
Sum
load
-
onFinish -
onError -
onProgress
Loads all resources.
Parameters:
-
onFinishFunctionCalled when all resource is loaded
-
onErrorFunctionCalled when an error happens
-
onProgressFunctionCalled when a resource is loaded or progress changed
scene
-
name -
url -
settings
Creates a new JSONSceneSource, and adds to the collection.
Parameters:
-
nameStringKey
-
urlStringScene JSON URL
-
settingsObjectSettings passed as constructor parameter to JSONSceneSource.
Returns:
The created JSONSceneSource
sprite
-
name -
url -
settings
Creates a new sprite and adds to the collection.
Parameters:
-
nameStringKey
-
urlStringSprite URL
-
settingsObjectSettings passed to the Sprite constructor
Returns:
The defined sprite
tile
-
url -
width -
height -
sprites
Creates multiple sprites and adds to the collection. The sprites should have the same dimensions.
Parameters:
-
urlStringImage url
-
widthNumberWidth of all sprite
-
heightNumberHeight of all sprite
-
spritesObjectSprite names and positions as key:[left, top, subimages] The positions array is multiplied with the width and height, and the 'subimages' part is optional.
Returns:
The created sprites by name
Properties
prefix
String
When you create new items with the helpers(sprite(), audio()) this prefix is added to the url. Does NOT affect resources you manually add to the collection.
