Class Layer

Constructors

Properties

data?: (null | number)[]

The tiles data of the layer.

id: number = 0

The unique identifier of the layer.

image?: HTMLImageElement

The image of the image layer.

layerCanvas?: HTMLCanvasElement

The canvas element for the layer.

layerContext?: CanvasRenderingContext2D

The rendering context of the layer canvas.

name?: string

The name of the layer (optional).

objects?: Entity[]

The objects in the layer.

offset: Vector = ...

The offset of the layer.

parallax: Vector = ...

The parallax factor of the layer.

properties: Record<string, any> = {}

The properties of the layer.

renderOrder: number = 0

The render order of the layer.

repeatX: boolean = false

The repeatX mode for the image layer.

repeatY: boolean = false

The repeatY mode for the image layer.

scene: Scene
size: Vector = ...

The size of the layer.

tint?: Color

The tint color of the layer.

type: string = ...

The type of the layer.

visible: boolean = true

Flag indicating whether the layer is visible.

Methods

  • Draws a tile at the specified index on the layer.

    Parameters

    • tileId: number

      The ID of the tile to draw.

    • index: number

      The index of the tile on the layer.

    Returns void

  • Draws the layer canvas to the main context at the specified position and size.

    Parameters

    • pos: Vector

      The position to draw the layer canvas.

    • size: Vector

      The size of the layer canvas.

    Returns void

  • Iterates over each visible object in the layer and invokes the provided callback function. The callback function receives the object as a parameter.

    Parameters

    • cb: ((obj: Entity) => void)

      The callback function to be invoked for each visible object.

        • (obj): void
        • Parameters

          Returns void

    Returns void

  • Iterates over each visible tile and executes the provided callback function.

    Parameters

    • fn: ((tile: Tile, pos: Vector, flipH: boolean, flipV: boolean) => void)

      The callback function to execute for each visible tile. It receives the tile object, position, and flips as parameters.

        • (tile, pos, flipH, flipV): void
        • Parameters

          Returns void

    Returns void

  • Retrieves the tile at the specified position.

    Parameters

    • pos: Vector

      The position of the tile.

    Returns null | number

    The tile at the specified position, or null if the position is out of range or the data is not available.

  • Post-update method. This method is called after the update and draw. It can be used to perform additional operations after the update.

    Returns void

  • Sets the tile at the specified position.

    Parameters

    • pos: Vector

      The position of the tile.

    • tileId: number

      The ID of the tile to set.

    Returns void