Options
All
  • Public
  • Public/Protected
  • All
Menu

A tile-map asset.

Usually this asset defines a specific level or area in a game.

Contrary to the name, this is not necessary a tile-map. The contents are defined by the layers that are added to it, which could also include only image and object layers. Yet, this class has many properties that affect how the tile layers are rendered.

Hierarchy

Index

Constructors

constructor

Properties

Readonly asset

asset: null | Asset

The asset this object is part of, or null.

Readonly assetType

assetType: AssetType

The type of this asset.

since

1.11

backgroundColor

backgroundColor: color

Background color of the map.

className

className: string

Class name of the object.

Replaced the "type" of MapObject and Tile in Tiled 1.9.

since

1.9

currentLayer

currentLayer: Layer

The current layer.

Readonly currentLayerChanged

currentLayerChanged: Signal<void>

The signal emitted when currentLayer changes.

Readonly fileName

fileName: string

File name of the asset.

Readonly fileNameChanged

fileNameChanged: Signal<string>

The signal emitted when fileName changes.

Its first parameter is the new file name, the second parameter is the old file name.

height

height: number

Height of the map in tiles (only relevant for non-infinite maps).

hexSideLength

hexSideLength: number

Length of the side of a hexagonal tile (used by tile layers on hexagonal maps).

infinite

infinite: boolean

Whether this map is infinite.

Readonly isTileMap

isTileMap: boolean

Whether the asset is a TileMap.

Readonly isTileset

isTileset: boolean

Whether the asset is a Tileset.

Readonly layerCount

layerCount: number

Number of top-level layers the map has.

layerDataFormat

layerDataFormat: typeof XML | typeof Base64 | typeof Base64Gzip | typeof Base64Zlib | typeof Base64Zstandard | typeof CSV

The format in which the layer data is stored, taken into account by TMX, JSON and Lua map formats.

Readonly layers

layers: Layer[]

The top-level layers of this map. To access nested layers, use GroupLayer.layers.

since

1.8

Readonly modified

modified: boolean

Whether the asset was modified after it was saved or loaded.

Readonly modifiedChanged

modifiedChanged: Signal<void>

The signal emitted when modified changes.

orientation

orientation: typeof Unknown | typeof Orthogonal | typeof Isometric | typeof Staggered | typeof Hexagonal

General map orientation

parallaxOrigin

parallaxOrigin: point

The parallax origin used for reference when applying the respective parallax factor.

since

1.8

Readonly readOnly

readOnly: boolean

Whether the object is read-only.

Readonly regionEdited

regionEdited: Signal<region>

The signal emitted after a region of a TileLayer was edited.

This signal is not emitted on undo/redo, nor after changes made in scripts. It receives the affected TileLayer as a second parameter.

renderOrder

renderOrder: typeof RightDown | typeof RightUp | typeof LeftDown | typeof LeftUp

Tile rendering order (only implemented for orthogonal maps)

Readonly selectedArea

selectedArea: SelectedArea

The selected area of tiles.

selectedLayers

selectedLayers: Layer[]

Selected layers.

The order of the layers is always bottom to top, with selected group layers coming after any of their selected children.

Readonly selectedLayersChanged

selectedLayersChanged: Signal<void>

The signal emitted when selectedLayers changes.

selectedObjects

selectedObjects: MapObject[]

Selected objects.

The order of the objects is their display order (when ObjectGroup.IndexOrder is used).

Readonly selectedObjectsChanged

selectedObjectsChanged: Signal<void>

The signal emitted when selectedObjects changes.

Readonly size

size: size

Size of the map in tiles (only relevant for non-infinite maps).

staggerAxis

staggerAxis: typeof StaggerX | typeof StaggerY

For staggered and hexagonal maps, determines which axis (X or Y) is staggered.

staggerIndex

staggerIndex: typeof StaggerOdd | typeof StaggerEven

For staggered and hexagonal maps, determines whether the even or odd indexes along the staggered axis are shifted.

tileHeight

tileHeight: number

Tile height (used by tile layers).

tileWidth

tileWidth: number

Tile width (used by tile layers).

Readonly tilesets

tilesets: Tileset[]

The list of tilesets referenced by this map. To determine which tilesets are actually used, call usedTilesets.

width

width: number

Width of the map in tiles (only relevant for non-infinite maps).

Static Readonly Base64

Base64: typeof Base64

Static Readonly Base64Gzip

Base64Gzip: typeof Base64Gzip

Static Readonly Base64Zlib

Base64Zlib: typeof Base64Zlib

Static Readonly Base64Zstandard

Base64Zstandard: typeof Base64Zstandard

Static Readonly CSV

CSV: typeof CSV

Static Readonly Hexagonal

Hexagonal: typeof Hexagonal

Static Readonly Isometric

Isometric: typeof Isometric

Static Readonly LeftDown

LeftDown: typeof LeftDown

Static Readonly LeftUp

LeftUp: typeof LeftUp

Static Readonly Orthogonal

Orthogonal: typeof Orthogonal

Static Readonly RightDown

RightDown: typeof RightDown

Static Readonly RightUp

RightUp: typeof RightUp

Static Readonly StaggerEven

StaggerEven: typeof StaggerEven

Static Readonly StaggerOdd

StaggerOdd: typeof StaggerOdd

Static Readonly StaggerX

StaggerX: typeof StaggerX

Static Readonly StaggerY

StaggerY: typeof StaggerY

Static Readonly Staggered

Staggered: typeof Staggered

Static Readonly Unknown

Unknown: typeof Unknown

Static Readonly XML

XML: typeof XML

Methods

addLayer

  • addLayer(layer: Layer): void
  • Adds the layer to the map, above all existing layers. The layer can’t already be part of a map.

addTileset

  • addTileset(tileset: Tileset): boolean
  • Adds the given tileset to the list of tilesets referenced by this map. Returns true if the tileset was added, or false if the tileset was already referenced by this map.

autoMap

  • autoMap(rulesOrMapFile?: string): void
  • autoMap(region: rect | region, rulesOrMapFile?: string): void
  • Applies Automapping using the given rules file or rule map file.

    When no rules file nor rule map file is given, Automapping is applied using the default rules file.

    note

    This operation can only be applied to maps loaded from a file.

  • Applies Automapping in the given region using the given rules file or rule map file.

    When no rules file nor rule map file is given, Automapping is applied using the default rules file.

    note

    This operation can only be applied to maps loaded from a file.

insertLayerAt

  • insertLayerAt(index: number, layer: Layer): void
  • Inserts the layer at the given index. The layer can’t already be part of a map.

layerAt

  • layerAt(index: number): Layer
  • Returns a reference to the top-level layer at the given index. When the layer gets removed from the map, the reference changes to a standalone copy of the layer.

macro

  • macro<T>(text: string, callback: () => T): T
  • Creates a single undo command that wraps all changes applied to this asset by the given callback. Recommended to avoid spamming the undo stack with small steps that the user does not care about.

    Example function that changes visibility of multiple layers in one step:

    tileMap.macro((visible ? "Show" : "Hide") + " Selected Layers", function() {
        tileMap.selectedLayers.forEach(function(layer) {
            layer.visible = visible
        })
    })
    

    The returned value is whatever the callback function returned.

merge

  • merge(map: TileMap, canJoin?: boolean): void
  • Merges the tile layers in the given map with this one. If only a single tile layer exists in the given map, it will be merged with the currentLayer.

    Normally, merging tile layers will ignore empty areas in the source map. However, when edits to tile layers in the source map have previously been made through TileLayerEdit.setTile, these edits are applied regardless of whether the tiles are empty or not. This enables erasing of tiles, for example when merging the Tool.preview.

    This operation can currently only be applied to maps open in the editor.

    If canJoin is true, the operation joins with the previous one on the undo stack when possible. Useful for reducing the amount of undo commands.

pixelToScreen

  • pixelToScreen(x: number, y: number): point
  • pixelToScreen(position: point): point
  • Converts the given position from pixel to screen coordinates.

  • Converts the given position from pixel to screen coordinates.

pixelToTile

  • pixelToTile(x: number, y: number): point
  • pixelToTile(position: point): point
  • Converts the given position from pixel to tile coordinates.

  • Converts the given position from pixel to tile coordinates.

properties

  • Returns all custom properties set on this object.

    Modifications to the properties will not affect the original object. Does not include inherited values (see resolvedProperties).

property

  • Returns the value of the custom property with the given name, or undefined if no such property is set on the object. Does not include inherited values (see resolvedProperty).

    file properties are returned as FilePath.

    object properties are returned as MapObject when possible, or ObjectRef when the object could not be found.

redo

  • redo(): void
  • Redoes the last change that was undone.

    note

    The undo system is only enabled for assets loaded in the editor!

removeLayer

  • removeLayer(layer: Layer): void
  • Removes the given layer from the map. The reference to the layer becomes a standalone copy.

removeLayerAt

  • removeLayerAt(index: number): void
  • Removes the top-level layer at the given index. When a reference to the layer still exists, that reference becomes a standalone copy of the layer.

removeObjects

  • Removes the given objects from this map. The object references turn into a standalone copy of the object.

    since

    1.8

removeProperty

  • removeProperty(name: string): void

removeTileset

  • removeTileset(tileset: Tileset): boolean
  • Removes the given tileset from the list of tilesets referenced by this map. Returns true on success, or false when the given tileset was not referenced by this map or when the tileset was still in use by a tile layer or tile object.

replaceTileset

  • Replaces all occurrences of oldTileset with newTileset. Returns true on success, or false when either the old tileset was not referenced by the map, or when the new tileset was already referenced by the map.

resize

  • resize(size: size, offset?: point, removeObjects?: boolean): void
  • Resizes the map to the given size, optionally applying an offset (in tiles).

    This operation can currently only be applied to maps loaded from a file.

    See also setSize.

resolvedProperties

  • Returns all custom properties set on this object. Modifications to the properties will not affect the original object. Includes values inherited from object types, templates and tiles where applicable.

resolvedProperty

  • Returns the value of the custom property with the given name, or undefined if no such property is set. Includes values inherited from object types, templates and tiles where applicable.

save

  • save(): boolean
  • Save this asset to disk. Returns true if the asset was saved successfully.

    Errors are reported by the UI. When an editor is open for this asset, this editor is activated when an error is reported.

    Only supported with the editor running, not when running scripts on the CLI. Also, the asset should already have an associated file.

    To save assets to a specific file or in a different format, use tiled.mapFormat or tiled.tilesetFormat. This is currently not supported for worlds.

    since

    1.11

screenToPixel

  • screenToPixel(x: number, y: number): point
  • screenToPixel(position: point): point
  • Converts the given position from screen to pixel coordinates.

  • Converts the given position from screen to pixel coordinates.

screenToTile

  • screenToTile(x: number, y: number): point
  • screenToTile(position: point): point
  • Converts the given position from screen to tile coordinates.

  • Converts the given position from screen to tile coordinates.

setColorProperty

  • setColorProperty(name: string, value: color): void
  • setColorProperty(name: string, red: number, green: number, blue: number, alpha?: number): void
  • Sets the value of the custom property with the given name to the given color value.

    The color is specified as a string "#RGB", "#RRGGBB" or "#AARRGGBB".

    since

    1.10

    deprecated

    Use setProperty with a value created by tiled.color instead.

  • Sets the value of the custom property with the given name to the given color value.

    The color is specified by its red, green, blue and alpha components. Each component takes a value from 0 to 255. When not provided, the alpha defaults to 255.

    since

    1.10

    deprecated

    Use setProperty with a value created by tiled.color instead.

setFloatProperty

  • setFloatProperty(name: string, value: number): void
  • Sets the value of the custom property with the given name to the given float value.

    This function is provided as alternative to setProperty, since that function will set whole numbers as int properties.

    since

    1.10

setProperties

  • Replaces all currently set custom properties with a new set of properties.

setProperty

  • Sets the value of the custom property with the given name.

    Supported types are bool, number, string, color, FilePath, ObjectRef, MapObject and PropertyValue.

    note

    When setting a number, the property type will be set to either int or float, depending on whether it is a whole number. To force the property to be float, use setFloatProperty.

  • Sets the value of an object's property identified by the given path to the given value.

    The path is a list of property names, where each name identifies a member of the previous member's value. The last name in the list identifies the property to set.

    Supported types are bool, number, string, color, FilePath, ObjectRef, MapObject and PropertyValue.

    note

    When setting a number, the property type will be set to either int or float, depending on whether it is a whole number. To force the property to be float, use setFloatProperty.

    since

    1.11

setSize

  • setSize(width: number, height: number): void
  • Sets the size of the map in tiles. This does not affect the contents of the map.

    See also resize.

setTileSize

  • setTileSize(width: number, height: number): void
  • Sets the tile size of the map in pixels. This affects the rendering of all tile layers.

tileToPixel

  • tileToPixel(x: number, y: number): point
  • tileToPixel(position: point): point
  • Converts the given position from tile to pixel coordinates.

  • Converts the given position from tile to pixel coordinates.

tileToScreen

  • tileToScreen(x: number, y: number): point
  • tileToScreen(position: point): point
  • Converts the given position from tile to screen coordinates.

  • Converts the given position from tile to screen coordinates.

toImage

  • Renders the map to an image. When no size is given, creates an image the size of the map.

    warning

    A tile map can easily be way too large to render to an image unscaled, so be careful when calling this function.

    since

    1.10

undo

  • undo(): void
  • Undoes the last applied change.

    note

    The undo system is only enabled for assets loaded in the editor!

usedTilesets

  • Returns the list of tilesets actually used by this map. This is generally a subset of the tilesets referenced by the map (the tilesets property).

Generated using TypeDoc