Skip to main content
Version: Phaser v4.0.0

ImageCollection

An Image Collection is a special Tile Set where each entry is a complete, individual image rather than a tile sliced from a larger spritesheet. Unlike a standard Tile Set, every image in the collection is its own standalone asset referenced by a unique global ID (GID).

Image Collections are normally created automatically when Tiled map data is loaded. You would encounter them when a Tiled map uses the "Collection of Images" tile set type instead of the standard single-image tile set type.

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#L52
Since: 3.0.0


imageHeight

imageHeight: number

Description:

The height of the tallest image (in pixels).

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


imageMargin

imageMargin: number

Description:

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

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


images

images: array

Description:

The cached images that are a part of this collection.

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


imageSpacing

imageSpacing: number

Description:

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

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


imageWidth

imageWidth: number

Description:

The width of the widest image (in pixels).

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


name

name: string

Description:

The name of the Image Collection.

Source: src/tilemaps/ImageCollection.js#L43
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#L102
Since: 3.0.0


total

total: number

Description:

The total number of images in the image collection.

Source: src/tilemaps/ImageCollection.js#L121
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 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#L147
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#L132
Since: 3.0.0