# Class: Tileset

## Phaser. Tileset

Phaser.Tileset

#### new Tileset(name, firstgid, width, height, margin, spacing, properties)

  A Tile set is a combination of an image containing the tiles and collision data per tile. You should not normally instantiate this class directly.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `name` | string |  |  | The name of the tileset in the map data.
  `firstgid` | number |  |  | The Tiled firstgid value. In non-Tiled data this should be considered the starting index value of the first tile in this set.
  `width` | number | <optional> | 32 | Width of each tile in pixels.
  `height` | number | <optional> | 32 | Height of each tile in pixels.
  `margin` | number | <optional> | 0 | The amount of margin around the tilesheet.
  `spacing` | number | <optional> | 0 | The amount of spacing between each tile in the sheet.
  `properties` | object | <optional> |  | Tileset properties.

  Source:
    - tilemap/Tileset.js, line 21

### Members

#### columns

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `columns` | number | The number of columns in the tile sheet.

  Source:
    - tilemap/Tileset.js, line 76

#### firstgid

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `firstgid` | number | The Tiled firstgid value. In non-Tiled data this should be considered the starting index value of the first tile in this set.

  Source:
    - tilemap/Tileset.js, line 36

#### image

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `image` | object | The image used for rendering. This is a reference to the image stored in Phaser.Cache.

  Source:
    - tilemap/Tileset.js, line 66

#### name

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `name` | string | The name of the Tileset.

  Source:
    - tilemap/Tileset.js, line 31

#### properties

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `properties` | object | Tileset specific properties (typically defined in the Tiled editor).

  Source:
    - tilemap/Tileset.js, line 61

#### rows

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `rows` | number | The number of rows in the tile sheet.

  Source:
    - tilemap/Tileset.js, line 71

#### tileHeight

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `tileHeight` | number | The height of a tile in pixels.

  Source:
    - tilemap/Tileset.js, line 46

#### tileMargin

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `tileMargin` | number | The margin around the tiles in the tileset.

  Source:
    - tilemap/Tileset.js, line 51

#### tileSpacing

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `tileSpacing` | number | The spacing in pixels between each tile in the tileset.

  Source:
    - tilemap/Tileset.js, line 56

#### tileWidth

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `tileWidth` | number | The width of a tile in pixels.

  Source:
    - tilemap/Tileset.js, line 41

#### total

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `total` | number | The total number of tiles in the tilesheet.

  Source:
    - tilemap/Tileset.js, line 81

### Methods

#### draw(context, x, y, index)

  Draws a tile from this Tileset at the given coordinates on the context.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `context` | HTMLCanvasContext | The context to draw the tile onto.
  `x` | number | The x coordinate to draw to.
  `y` | number | The y coordinate to draw to.
  `index` | number | The index of the tile within the set to draw.

  Source:
    - tilemap/Tileset.js, line 93

#### setImage(image)

  Adds a reference from this Tileset to an Image stored in the Phaser.Cache.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `image` | Image | The image this tileset will use to draw with.

  Source:
    - tilemap/Tileset.js, line 123

#### setSpacing(tileMargin, tileSpacing)

  Sets tile spacing and margins.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `tileMargin` | number | <optional> | The margin around the tiles in the sheet.
  `tileSpacing` | number | <optional> | The spacing between the tiles in the sheet.

  Source:
    - tilemap/Tileset.js, line 159