# Class: TilemapLayer

## Phaser. TilemapLayer

Phaser.TilemapLayer

#### new TilemapLayer(game, tilemap, index, width, height)

  A Tilemap Layer is a set of map data combined with a Tileset in order to render that data to the game.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `game` | Phaser.Game | Game reference to the currently running game.
  `tilemap` | Phaser.Tilemap | The tilemap to which this layer belongs.
  `index` | number | The layer index within the map that this TilemapLayer represents.
  `width` | number | Width of the renderable area of the layer.
  `height` | number | Height of the renderable area of the layer.

  Source:
    - tilemap/TilemapLayer.js, line 18

### Members

#### baseTexture

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `baseTexture` | PIXI.BaseTexture | Required Pixi var.

  Source:
    - tilemap/TilemapLayer.js, line 53

#### cameraOffset

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `cameraOffset` | Phaser.Point | If this object is fixed to the camera then use this Point to specify how far away from the Camera x/y it's rendered.

  Source:
    - tilemap/TilemapLayer.js, line 88

#### canvas

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `canvas` | HTMLCanvasElement | The canvas to which this TilemapLayer draws.

  Source:
    - tilemap/TilemapLayer.js, line 43

#### collisionHeight

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `collisionHeight` | number | The height of the collision tiles.

  Source:
    - tilemap/TilemapLayer.js, line 781

#### collisionWidth

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `collisionWidth` | number | The width of the collision tiles.

  Source:
    - tilemap/TilemapLayer.js, line 761

#### context

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `context` | CanvasRenderingContext2D | The 2d context of the canvas.

  Source:
    - tilemap/TilemapLayer.js, line 48

#### debug

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `debug` | boolean | If set to true the collideable tile edges path will be rendered. Only works when game is running in Phaser.CANVAS mode.

  Default Value:
    - false
  Source:
    - tilemap/TilemapLayer.js, line 100

#### debugAlpha

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `debugAlpha` | number | If debug is true then the tileset is rendered with this alpha level, to make the tile edges clearer.

  Default Value:
    - 0.5
  Source:
    - tilemap/TilemapLayer.js, line 106

#### debugCallbackColor

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `debugCallbackColor` | string | If debug is true this is the color used to outline the edges of tiles that have collision callbacks. Provide in hex or rgb/rgba string format.

  Default Value:
    - "rgba(255, 0, 0, 1)"
  Source:
    - tilemap/TilemapLayer.js, line 130

#### debugColor

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `debugColor` | string | If debug is true this is the color used to outline the edges of collidable tiles. Provide in hex or rgb/rgba string format.

  Default Value:
    - "rgba(0, 255, 0, 1)"
  Source:
    - tilemap/TilemapLayer.js, line 112

#### debugFill

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `debugFill` | boolean | If true the debug tiles are filled with debugFillColor AND stroked around.

  Default Value:
    - false
  Source:
    - tilemap/TilemapLayer.js, line 118

#### debugFillColor

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `debugFillColor` | string | If debugFill is true this is the color used to fill the tiles. Provide in hex or rgb/rgba string format.

  Default Value:
    - "rgba(0, 255, 0, 0.2)"
  Source:
    - tilemap/TilemapLayer.js, line 124

#### dirty

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `dirty` | boolean | Flag controlling when to re-render the layer.

  Source:
    - tilemap/TilemapLayer.js, line 151

#### fixedToCamera

  An object that is fixed to the camera ignores the position of any ancestors in the display list and uses its x/y coordinates as offsets from the top left of the camera.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `fixedToCamera` | boolean | Fixes this object to the Camera.

  Default Value:
    - true
  Source:
    - tilemap/TilemapLayer.js, line 83

#### game

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `game` | Phaser.Game | A reference to the currently running Game.

  Source:
    - tilemap/TilemapLayer.js, line 23

#### index

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `index` | number | The index of this layer within the Tilemap.

  Source:
    - tilemap/TilemapLayer.js, line 33

#### layer

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `layer` | object | The layer object within the Tilemap that this layer represents.

  Source:
    - tilemap/TilemapLayer.js, line 38

#### map

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `map` | Phaser.Tilemap | The Tilemap to which this layer is bound.

  Source:
    - tilemap/TilemapLayer.js, line 28

#### name

  ##### Properties:

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

  Source:
    - tilemap/TilemapLayer.js, line 70

#### rayStepRate

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `rayStepRate` | number | When ray-casting against tiles this is the number of steps it will jump. For larger tile sizes you can increase this to improve performance.

  Default Value:
    - 4
  Source:
    - tilemap/TilemapLayer.js, line 157

#### scrollFactorX

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `scrollFactorX` | number | speed at which this layer scrolls horizontally, relative to the camera (e.g. scrollFactorX of 0.5 scrolls half as quickly as the 'normal' camera-locked layers do)

  Default Value:
    - 1
  Source:
    - tilemap/TilemapLayer.js, line 138

#### scrollFactorY

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `scrollFactorY` | number | speed at which this layer scrolls vertically, relative to the camera (e.g. scrollFactorY of 0.5 scrolls half as quickly as the 'normal' camera-locked layers do)

  Default Value:
    - 1
  Source:
    - tilemap/TilemapLayer.js, line 146

#### scrollX

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `scrollX` | number | Scrolls the map horizontally or returns the current x position.

  Source:
    - tilemap/TilemapLayer.js, line 681

#### scrollY

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `scrollY` | number | Scrolls the map vertically or returns the current y position.

  Source:
    - tilemap/TilemapLayer.js, line 721

#### texture

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `texture` | PIXI.Texture | Required Pixi var.

  Source:
    - tilemap/TilemapLayer.js, line 58

#### textureFrame

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `textureFrame` | Phaser.Frame | Dimensions of the renderable area.

  Source:
    - tilemap/TilemapLayer.js, line 63

#### tileColor

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `tileColor` | string | If no tileset is given the tiles will be rendered as rectangles in this color. Provide in hex or rgb/rgba string format.

  Default Value:
    - "rgb(255, 255, 255)"
  Source:
    - tilemap/TilemapLayer.js, line 94

#### type

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `type` | number | The const type of this object.

  Source:
    - tilemap/TilemapLayer.js, line 76

### Methods

#### getRayCastTiles(line, stepRate, collides, interestingFace) → {array.<Phaser.Tile>}

  Gets all tiles that intersect with the given line.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `line` | Phaser.Line |  |  | The line used to determine which tiles to return.
  `stepRate` | number | <optional> |  | How many steps through the ray will we check? If undefined or null it uses TilemapLayer.rayStepRate.
  `collides` | boolean | <optional> | false | If true only return tiles that collide on one or more faces.
  `interestingFace` | boolean | <optional> | false | If true only return tiles that have interesting faces.

  Source:
    - tilemap/TilemapLayer.js, line 384

  ##### Returns:

  An array of Phaser.Tiles.

  Type
    array.<Phaser.Tile>

#### getTiles(x, y, width, height, collides, interestingFace) → {array.<Phaser.Tile>}

  Get all tiles that exist within the given area, defined by the top-left corner, width and height. Values given are in pixels, not tiles.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `x` | number |  |  | X position of the top left corner.
  `y` | number |  |  | Y position of the top left corner.
  `width` | number |  |  | Width of the area to get.
  `height` | number |  |  | Height of the area to get.
  `collides` | boolean | <optional> | false | If true only return tiles that collide on one or more faces.
  `interestingFace` | boolean | <optional> | false | If true only return tiles that have interesting faces.

  Source:
    - tilemap/TilemapLayer.js, line 430

  ##### Returns:

  An array of Phaser.Tiles.

  Type
    array.<Phaser.Tile>

#### getTileX(x) → {Phaser.Tile}

  Convert a pixel value to a tile coordinate.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `x` | number | X position of the point in target tile.

  Source:
    - tilemap/TilemapLayer.js, line 336

  ##### Returns:

  The tile with specific properties.

  Type
    Phaser.Tile

#### getTileXY(x, y, point) → {Phaser.Point|object}

  Convert a pixel value to a tile coordinate.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `x` | number | X position of the point in target tile.
  `y` | number | Y position of the point in target tile.
  `point` | Phaser.Point | object | The Point object to set the x and y values on.

  Source:
    - tilemap/TilemapLayer.js, line 366

  ##### Returns:

  A Point object with its x and y properties set.

  Type
    Phaser.Point | object

#### getTileY(y) → {Phaser.Tile}

  Convert a pixel value to a tile coordinate.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `y` | number | Y position of the point in target tile.

  Source:
    - tilemap/TilemapLayer.js, line 351

  ##### Returns:

  The tile with specific properties.

  Type
    Phaser.Tile

#### postUpdate()

  Automatically called by World.postUpdate. Handles cache updates.

  Source:
    - tilemap/TilemapLayer.js, line 201

#### render()

  Renders the tiles to the layer canvas and pushes to the display.

  Source:
    - tilemap/TilemapLayer.js, line 516

#### renderDebug()

  Renders a collision debug overlay on-top of the canvas. Called automatically by render when debug = true.

  Source:
    - tilemap/TilemapLayer.js, line 611

#### resizeWorld()

  Sets the world size to match the size of this layer.

  Source:
    - tilemap/TilemapLayer.js, line 234

#### updateMax()

  Internal function to update maximum values.

  Source:
    - tilemap/TilemapLayer.js, line 489