API Docs for: v0.1.0
Show:

Cache Class

Extends Object
Defined in: src\utils\Cache.js:11

A game only has one instance of a Cache and it is used to store all externally loaded assets such as images, sounds and data files as a result of Loader calls. Cache items use string based keys for look-up.

Constructor

Cache

(
  • game
)

Parameters:

  • game Game

    The game instance this cache belongs to

Methods

(
  • key
)
Texture

Get a Texture by key.

Parameters:

  • key String

    Asset key of the RenderTexture you want.

Returns:

addAudio

(
  • obj
)

Add a new sound.

Parameters:

  • obj Object

    The audio file object

    • key String

      Asset key for the audio.

    • url String

      URL of this audio file.

    • data ArrayBuffer | Audio

      The loaded audio data

    • webAudio Boolean

      Is this a webAudio ArrayBuffer for a sound?

    • decoded Boolean

      Is the data decoded yet?

addBitmapFont

(
  • obj
)

Add a new Bitmap Font.

Parameters:

  • obj Object

    The bitmap font file object

    • key String

      Asset key for the font texture.

    • url String

      URL of this font xml file.

    • data Object

      Extra font data.

    • format Number

      The format of the bitmap font data

(
  • key
)
Texture

Get a Texture by key.

Parameters:

  • key String

    Asset key of the RenderTexture you want.

Returns:

addCanvas

(
  • obj
)

Add a new canvas.

Parameters:

  • obj Object

    The spritesheet object

    • key String

      Asset key for this canvas.

    • canvas HTMLCanvasElement

      Canvas DOM element.

    • context CanvasRenderingContext2D

      Render context of this canvas.

(
  • key
)
Texture

Get a Bitmap Font by key.

Parameters:

  • key String

    Asset key of the Bitmap Font you want.

Returns:

addImage

(
  • obj
)

Add a new image.

Parameters:

  • obj Object

    The image file object

    • key String

      Asset key for the image.

    • url String

      URL of this image file.

    • image Image

      The image object that was loaded

addSpriteSheet

(
  • obj
)

Add a new sprite sheet.

Parameters:

  • obj Object

    The spritesheet object

    • key String

      Asset key for the sprite sheet.

    • url String

      URL of this sprite sheet file.

    • image Image

      The image of the sprite sheet

    • frameWidth Number

      Width of the sprite sheet.

    • frameHeight Number

      Height of the sprite sheet.

    • frameMax Number

      How many frames stored in the sprite sheet.

addText

(
  • obj
)

Add a new text data.

Parameters:

  • obj Object

    The text file object

    • key String

      Asset key for the text data.

    • url String

      URL of this text data file.

    • data Object

      Extra text data.

addTextureAtlas

(
  • obj
)

Add a new texture atlas.

Parameters:

  • obj Object

    The texture atlas file object

    • key String

      Asset key for the texture atlas.

    • url String

      URL of this texture atlas file.

    • format Number

      The format of the atlas data ATLAS_FORMAT.JSON_ARRAY, ATLAS_FORMAT.JSON_HASH, or ATLAS_FORMAT.STARLING_XML

    • data Object

      The texture atlas data exported from TexturePacker

    • image Image

      The texture image

addTilemap

(
  • obj
)

Add a new tilemap.

Parameters:

  • obj Object

    The tilemap file object

    • key String

      Asset key for the tilemap

    • url String

      URL of the tilemap data file

    • data Object

      The loaded tilemap data

    • format Number

      The format of the tilemap data

    • [images] Array optional

      Array of images used in the tilesets of this tilemap

destroy

()

Destroys this object, removing references so the GC can cleanup

getAudio

(
  • key
)
Object

Get sound by key.

Parameters:

  • key String

    Asset key of the sound you want.

Returns:

Object:

getAudioData

(
  • key
)
ArrayBuffer | Audio

Get sound data by key.

Parameters:

  • key String

    Asset key of the sound you want.

Returns:

ArrayBuffer | Audio:

getCanvas

(
  • key
)
HTMLCanvasElement

Get canvas by key.

Parameters:

  • key String

    Asset key of the canvas you want.

Returns:

HTMLCanvasElement:

getImage

(
  • key
)
Image

Get image data by key.

Parameters:

  • key String

    Asset key of the image you want.

Returns:

Image:

getText

(
  • key
)
Object

Get text data by key.

Parameters:

  • key String

    Asset key of the text data you want.

Returns:

Object:

The text data you want.

getTilemap

(
  • key
)
Object

Get tilemap data by key.

Parameters:

  • key String

    Asset key of the tilemap you want.

Returns:

Object:

The tilemap file data. The map data is in the data property, the images (for tileset) are in images

removeCanvas

(
  • key
)

Remove a canvas by key.

Parameters:

  • key String

    key to remove

removeImage

(
  • key
)

Remove an image by key.

Parameters:

  • key String

    key to remove

removeSound

(
  • key
)

Remove a sound by key.

Parameters:

  • key String

    key to remove

removeText

(
  • key
)

Remove a text by key.

Parameters:

  • key String

    key to remove

Properties

_canvases

Object private

Canvas key-value container.

_images

Object private

Image key-value container.

_sounds

Object private

Sound key-value container.

_text

Object private

Text key-value container.

_tilemaps

Object private

Tilemap key-value container.

game

Game

Local reference to Game.