API Docs for: 1.0.1

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 Object

    Initial properties

Item Index

Properties

Methods

add

(
  • [name]
  • Resource
)

Adds a new resource to the collection.

Parameters:

  • [name] String optional

    The unique name of the resource

  • Resource Grape.Resource

audio

(
  • name
  • opts
  • url1
  • url2
  • url3
)
Grape.Audio

Creates an Audio resource and adds to the collection. Check Grape.Audio for more information.

Parameters:

  • name String

    Key

  • opts Object

    Audio options

  • url1 String

    Audio URL

  • url2 String

    Audio URL fallback if url1 extension is not supported

  • url3 String

    Audio URL fallback if url2 extension is not supported

Returns:

Grape.Audio:

The Audio resource

get

(
  • name
)
Grape.Resource

Get a previously added resource by name.

Parameters:

  • name String

    Name

Returns:

Grape.Resource:

the resource

getEstimatedTime

() Number

Returns the sum of the estimated time of all resource.

Returns:

Number:

Sum

load

(
  • onFinish
  • onError
  • onProgress
)

Loads all resources.

Parameters:

  • onFinish Function

    Called when all resource is loaded

  • onError Function

    Called when an error happens

  • onProgress Function

    Called when a resource is loaded or progress changed

scene

(
  • name
  • url
  • settings
)
Grape.JSONSceneSource

Creates a new JSONSceneSource, and adds to the collection.

Parameters:

  • name String

    Key

  • url String

    Scene JSON URL

  • settings Object

    Settings passed as constructor parameter to JSONSceneSource.

Returns:

Grape.JSONSceneSource:

The created JSONSceneSource

sprite

(
  • name
  • url
  • settings
)
Grape.Sprite

Creates a new sprite and adds to the collection.

Parameters:

  • name String

    Key

  • url String

    Sprite URL

  • settings Object

    Settings passed to the Sprite constructor

Returns:

Grape.Sprite:

The defined sprite

tile

(
  • url
  • width
  • height
  • sprites
)
Object

Creates multiple sprites and adds to the collection. The sprites should have the same dimensions.

Parameters:

  • url String

    Image url

  • width Number

    Width of all sprite

  • height Number

    Height of all sprite

  • sprites Object

    Sprite 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:

Object:

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.