Phaser API Documentation

  Version: 
Filter
This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . Tilemaps . ImageCollection

This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . Tilemaps . 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:

name type arguments Default description
name string

The name of the image collection in the map data.

firstgid number

The first image index this image collection contains.

width number <optional> 32

Width of widest image (in pixels).

height number <optional> 32

Height of tallest image (in pixels).

margin number <optional> 0

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

spacing number <optional> 0

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

properties object <optional> {}

Custom Image Collection properties.

Since: 3.0.0

Members

firstgid: number
Focus
Focus

Description:

The Tiled firstgid value. This is the starting index of the first image index this Image Collection contains.

Type:
number
Since: 3.0.0
Focus
Focus
<readonly> imageHeight: number
Focus
Focus

Description:

The height of the tallest image (in pixels).

Type:
number
Since: 3.0.0
Focus
Focus
<readonly> imageMarge: number
Focus
Focus

Description:

The margin around the images in the collection (in pixels). Use setSpacing to change.

Type:
number
Since: 3.0.0
Focus
Focus
<readonly> imageSpacing: number
Focus
Focus

Description:

The spacing between each image in the collection (in pixels). Use setSpacing to change.

Type:
number
Since: 3.0.0
Focus
Focus
<readonly> imageWidth: number
Focus
Focus

Description:

The width of the widest image (in pixels).

Type:
number
Since: 3.0.0
Focus
Focus
<readonly> images: array
Focus
Focus

Description:

The cached images that are a part of this collection.

Type:
array
Since: 3.0.0
Focus
Focus
name: string
Focus
Focus

Description:

The name of the Image Collection.

Type:
string
Since: 3.0.0
Focus
Focus
properties: object
Focus
Focus

Description:

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

Type:
object
Since: 3.0.0
Focus
Focus
<readonly> total: number
Focus
Focus

Description:

The total number of images in the image collection.

Type:
number
Since: 3.0.0
Focus
Focus

Methods

addImage(gid, image)
Focus
Focus

Description:

Add an image to this Image Collection.

Parameters:

name type description
gid number

The gid of the image in the Image Collection.

image string

The the key of the image in the Image Collection and in the cache.

Returns:
Description:

This ImageCollection object.

Examples:
Since: 3.0.0
Focus
Focus
containsImageIndex(imageIndex)
Focus
Focus

Description:

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

Parameters:

name type description
imageIndex number

The image index to search for.

Returns:
Description:

True if this Image Collection contains the given index.

Type:
  • boolean
Examples:
Since: 3.0.0
Focus
Focus