Skip to main content

Class: ImageManager

Fetches, loads, and provides images to the game.

Constructors

new ImageManager()

new ImageManager(game, baseUrls): ImageManager

Parameters

game: Game

baseUrls: GameBaseUrls

Returns

ImageManager

Defined in

ImageManager.ts:25

Properties

images

images: Record<string, M2Image> = {}

Defined in

ImageManager.ts:16


missingLocalizationImagePaint?

optional missingLocalizationImagePaint: Paint

Defined in

ImageManager.ts:23

Methods

addImage()

addImage(image): void

Internal

Adds a m2c2kit image (M2Image) to the images ready for the game.

For m2c2kit library use only

Parameters

image: M2Image

A m2c2kit image

Returns

void

Remarks

Typically, a programmer won't call this because images will be automatically rendered and loaded in initializeImages(). One reason this function is called in-game is when the game takes a screenshot and adds it as an outgoing image for transitions.

Defined in

ImageManager.ts:463


getImage()

getImage(imageName): M2Image

Internal

Returns a m2c2kit image (M2Image) that has been loaded by the ImageManager.

For m2c2kit library use only

Parameters

imageName: string

The name given to the previously rendered image

Returns

M2Image

A m2c2kit image

Remarks

Typically, a user won't call this because they use a higher-level abstraction (m2c2kit Sprite).

Defined in

ImageManager.ts:447


initializeImages()

initializeImages(browserImages): Promise<void>

Internal

Loads image assets and makes them ready to use during the game initialization.

For m2c2kit library use only

Parameters

browserImages: undefined | BrowserImage[]

array of BrowserImage objects

Returns

Promise<void>

A promise that completes when all images have loaded

Remarks

Typically, a user won't call this because the m2c2kit framework will call this automatically.

Defined in

ImageManager.ts:42


loadImages()

loadImages(browserImages): Promise<void>

Loads an array of images and makes them ready for the game.

Parameters

browserImages: BrowserImage[]

an array of BrowserImage

Returns

Promise<void>

A promise that completes when all images have loaded

Remarks

Using the browser's image rendering, this method converts the images (png, jpg, svg, or svg string) into m2c2kit images (M2Image). Rendering is an async activity, and thus this method returns a promise. Rendering of all images is done in parallel.

Defined in

ImageManager.ts:60


prepareDeferredImage()

prepareDeferredImage(image): Promise<void>

Internal

Makes ready to the game a m2c2kit image (M2Image) that was previously loaded, but whose browser rendering was deferred.

For m2c2kit library use only

Parameters

image: M2Image

M2Image to render and make ready

Returns

Promise<void>

A promise that completes when the image is ready

Defined in

ImageManager.ts:218


reinitializeLocalizedImages()

reinitializeLocalizedImages(): void

Sets an image to be re-rendered within the current locale.

Returns

void

Defined in

ImageManager.ts:180