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:
-
opts
ObjectInitial properties
Methods
add
-
[name]
-
Resource
Adds a new resource to the collection.
Parameters:
-
[name]
String optionalThe unique name of the resource
-
Resource
Grape.Resource
audio
-
name
-
opts
-
url1
-
url2
-
url3
Creates an Audio resource and adds to the collection. Check Grape.Audio for more information.
Parameters:
-
name
StringKey
-
opts
ObjectAudio options
-
url1
StringAudio URL
-
url2
StringAudio URL fallback if url1 extension is not supported
-
url3
StringAudio URL fallback if url2 extension is not supported
Returns:
The Audio resource
get
-
name
Get a previously added resource by name.
Parameters:
-
name
StringName
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:
-
onFinish
FunctionCalled when all resource is loaded
-
onError
FunctionCalled when an error happens
-
onProgress
FunctionCalled when a resource is loaded or progress changed
scene
-
name
-
url
-
settings
Creates a new JSONSceneSource, and adds to the collection.
Parameters:
-
name
StringKey
-
url
StringScene JSON URL
-
settings
ObjectSettings passed as constructor parameter to JSONSceneSource.
Returns:
The created JSONSceneSource
sprite
-
name
-
url
-
settings
Creates a new sprite and adds to the collection.
Parameters:
-
name
StringKey
-
url
StringSprite URL
-
settings
ObjectSettings 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:
-
url
StringImage url
-
width
NumberWidth of all sprite
-
height
NumberHeight of all sprite
-
sprites
ObjectSprite 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.