Skip to main content
Version: Phaser v3.88.2

ImageCollection

An Image Collection is a special Tile Set containing multiple images, with no slicing into each image.

Image Collections are normally created automatically when Tiled data is loaded.

Constructor

new ImageCollection(name, firstgid, [width], [height], [margin], [spacing], [properties])

Parameters

nametypeoptionaldefaultdescription
namestringNoThe name of the image collection in the map data.
firstgidnumberNoThe first image index this image collection contains.
widthnumberYes32Width of widest image (in pixels).
heightnumberYes32Height of tallest image (in pixels).
marginnumberYes0The margin around all images in the collection (in pixels).
spacingnumberYes0The spacing between each image in the collection (in pixels).
propertiesobjectYes"{}"Custom Image Collection properties.

Scope: static

Source: src/tilemaps/ImageCollection.js#L9
Since: 3.0.0

Public Members​

firstgid​

firstgid: number​

Description:

The Tiled firstgid value.

This is the starting index of the first image index this Image Collection contains.

Source: src/tilemaps/ImageCollection.js#L48
Since: 3.0.0


imageHeight​

imageHeight: number​

Description:

The height of the tallest image (in pixels).

Source: src/tilemaps/ImageCollection.js#L68
Since: 3.0.0


imageMarge​

imageMarge: number​

Description:

The margin around the images in the collection (in pixels).

Use setSpacing to change.

Source: src/tilemaps/ImageCollection.js#L78
Since: 3.0.0


images​

images: array​

Description:

The cached images that are a part of this collection.

Source: src/tilemaps/ImageCollection.js#L109
Since: 3.0.0


imageSpacing​

imageSpacing: number​

Description:

The spacing between each image in the collection (in pixels).

Use setSpacing to change.

Source: src/tilemaps/ImageCollection.js#L89
Since: 3.0.0


imageWidth​

imageWidth: number​

Description:

The width of the widest image (in pixels).

Source: src/tilemaps/ImageCollection.js#L58
Since: 3.0.0


name​

name: string​

Description:

The name of the Image Collection.

Source: src/tilemaps/ImageCollection.js#L39
Since: 3.0.0


properties​

properties: object​

Description:

Image Collection-specific properties that are typically defined in the Tiled editor.

Source: src/tilemaps/ImageCollection.js#L100
Since: 3.0.0


total​

total: number​

Description:

The total number of images in the image collection.

Source: src/tilemaps/ImageCollection.js#L119
Since: 3.0.0


Public Methods​

addImage​

<instance> addImage(gid, image, width, height)​

Description:

Add an image to this Image Collection.

Parameters:

nametypeoptionaldescription
gidnumberNoThe gid of the image in the Image Collection.
imagestringNoThe the key of the image in the Image Collection and in the cache.
widthnumberNoThe width of the image in the Image Collection.
heightnumberNoThe height of the image in the Image Collection.

Returns: Phaser.Tilemaps.ImageCollection - This ImageCollection object.

Source: src/tilemaps/ImageCollection.js#L145
Since: 3.0.0


containsImageIndex​

<instance> containsImageIndex(imageIndex)​

Description:

Returns true if and only if this image collection contains the given image index.

Parameters:

nametypeoptionaldescription
imageIndexnumberNoThe image index to search for.

Returns: boolean - True if this Image Collection contains the given index.

Source: src/tilemaps/ImageCollection.js#L130
Since: 3.0.0