API Docs for:
Show:

ResourceManager Class

Module: gs

Manages the resources of the game like graphics, audio, fonts, etc. It offers a lot of methods to easily access game resources and automatically caches them. So if an image is requested a second time it will be taken from the cache instead of loading it again.

Methods

add

(
  • name
  • data
)

Adds the specified resource to the context.

Parameters:

  • name String
    • A unique name for the resource like the file-path for example.
  • data gs.Bitmap | gs.AudioBuffer | gs.Video | gs.Live2DModel
    • The resource data like a gs.Bitmap object for example.

addCustomBitmap

(
  • bitmap
)

Adds a custom created bitmap to the resource manager.

Parameters:

  • bitmap gs.Bitmap
    • The bitmap to add.

createContext

()

Creates a new resource context. Use context to set the new created context as current context.

dispose

()

Disposes all resources.

disposeAudio

()

Disposes all audio resources associated with the current context.

disposeBitmaps

()

Disposes all bitmap resources associated with the current context.

disposeLive2D

()

Disposes all Live2D resources associated with the current context.

disposeVideos

()

Disposes all video resources associated with the current context.

fromDataBundle

()

Initializes the resource context from a data-bundle. Any already existing resource associations with this context will be deleted.

getAudioBuffer

(
  • filePath
)
gs.AudioBuffer

Gets an audio buffer. The audio data is fully loaded and decoded in memory. It is recommeneded for sound effects but for a long background music, getAudioStream should be used instead. That is especially the case on mobile devices.

Parameters:

  • filePath String
    • Path to the audio file.

Returns:

gs.AudioBuffer:

The audio buffer or null if no audio file exists at the specified file path.

getAudioStream

(
  • filePath
)
gs.AudioBuffer

Gets an audio stream.

Parameters:

  • filePath String
    • Path to the audio file.

Returns:

gs.AudioBuffer:

The audio buffer or null if no audio file exists at the specified file path.

getBitmap

(
  • filePath
  • hue
)
gs.Bitmap

Gets a bitmap.

Parameters:

  • filePath String
    • Path to the bitmap file.
  • hue Number
    • The bitmap's hue. The bitmap will be loaded and then recolored.

Returns:

gs.Bitmap:

The bitmap or null if no bitmap exists at the specified file path.

getCustomBitmap

(
  • key
)
gs.Bitmap

Gets a custom created bitmap by key.

Parameters:

  • key String
    • The key for the bitmap to get.

Returns:

gs.Bitmap:

The bitmap or null if no bitmap exists for the specified key.

getFont

(
  • name
  • size
)
gs.Font

Gets a font.

Parameters:

  • name String
    • The name of the font to get.
  • size Number
    • The size of the font to get.

Returns:

gs.Font:

The font or null if no font with the specified name exists.

getImage

(
  • filePath
)
HTMLImageElement

Gets an HTML image.

Parameters:

  • filePath String
    • Path to the image file.

Returns:

HTMLImageElement:

The image or null if no image exists at the specified file path.

getLive2DModel

(
  • filePath
)
gs.Live2DModel

Gets a Live2D model.

Parameters:

  • filePath String
    • Path to the Live2D model file.

Returns:

gs.Live2DModel:

The Live2D model or null if no model exists at the specified file path.

getVideo

(
  • filePath
)
gs.Video

Gets a video.

Parameters:

  • filePath String
    • Path to the video file.

Returns:

gs.Video:

The video or null if no video exists at the specified file path.

loadFonts

()

Loads all custom fonts in Graphics/Fonts folder.

remove

(
  • name
)

Removes the resource with the specified name from the context.

Parameters:

  • name String
    • The name of the resource to remove. For Example: The file name.

setCustomBitmap

(
  • key
  • bitmap
)

Sets a custom created bitmap for a specified key.

Parameters:

  • key String
    • The key for the bitmap to set.
  • bitmap gs.Bitmap
    • The bitmap to set.

toDataBundle

() String

Converts the resource context into a data-bundle for serialization. The data-bundle will only contain the names of the resources associated with this context but not the resource-data itself.

Returns:

String:

An array of resource names associated with this context.

update

()

Updates the loading process. Needs to be called once per frame to keep the ResourceManager up to date.

Properties

context

gs.ResourceManagerContext protected

Current resource context. All loaded resources will be associated with it. If current context is set to null, the systemContext is used instead.

context

gs.ResourceManagerContext

System resource context. All loaded system resources are associated with this context. Resources which are associated with the system context are not disposed until the game ends.

context

gs.ResourceManagerContext

Current resource context. All loaded resources will be associated with it. If current context is set to null, the systemContext is used instead.

customBitmapsByKey

Object protected

Holds in-memory created bitmaps.

events

gs.EventEmitter

resources

Object

All resources associated with this context.

resources

Object

Stores all loaded resources.

resourcesByPath

Object protected

Caches resources by file path.

resourcesByPath

Object protected

Caches resources by file path and HUE.

resourcesLoaded

Boolean

Indicates if all requested resources are loaded.