- Select ref document -

Tilemap API documentation

version 1.2.149

Functions and messages used to manipulate tile map components.

Functions

tilemap.get_bounds

tilemap.get_bounds(url)

Get the bounds for a tile map. This function returns multiple values: The lower left corner index x and y coordinates (1-indexed), the tile map width and the tile map height.

The resulting values take all tile map layers into account, meaning that the bounds are calculated as if all layers were collapsed into one.

Parameters

url

string | hash | url the tile map

url

string | hash | url the tile map

Returns

x

number x coordinate of the bottom left corner

y

number y coordinate of the bottom left corner

w

number number of columns (width) in the tile map

h

number number of rows (height) in the tile map

x

number x coordinate of the bottom left corner

y

number y coordinate of the bottom left corner

w

number number of columns (width) in the tile map

h

number number of rows (height) in the tile map

Examples

-- get the level bounds.
local x, y, w, h = tilemap.get_bounds("/level#tilemap")

tilemap.get_tile

tilemap.get_tile(url, layer, x, y)

Get the tile set at the specified position in the tilemap. The position is identified by the tile index starting at origo with index 1, 1. (see tilemap.set_tile()) Which tile map and layer to query is identified by the URL and the layer name parameters.

Parameters

url

string | hash | url the tile map

layer

string | hash name of the layer for the tile

x

number x-coordinate of the tile

y

number y-coordinate of the tile

url

string | hash | url the tile map

layer

string | hash name of the layer for the tile

x

number x-coordinate of the tile

y

number y-coordinate of the tile

Returns

tile

number index of the tile

tile

number index of the tile

Examples

-- get the tile under the player.
local tileno = tilemap.get_tile("/level#tilemap", "foreground", self.player_x, self.player_y)

tilemap.reset_constant

tilemap.reset_constant(url, constant)

Resets a shader constant for a tile map component. The constant must be defined in the material assigned to the tile map. Resetting a constant through this function implies that the value defined in the material will be used. Which tile map to reset a constant for is identified by the URL.

Parameters

url

string | hash | url the tile map that should have a constant reset

constant

string | hash name of the constant

url

string | hash | url the tile map that should have a constant reset

constant

string | hash name of the constant

Examples

The following examples assumes that the tile map has id "tilemap" and that the default-material in builtins is used, which defines the constant "tint". If you assign a custom material to the tile map, you can reset the constants defined there in the same manner.

How to reset the tinting of a tile map:

function init(self)
    tilemap.reset_constant("#tilemap", "tint")
end

tilemap.set_constant

tilemap.set_constant(url, constant, value)

Sets a shader constant for a tile map component. The constant must be defined in the material assigned to the tile map. Setting a constant through this function will override the value set for that constant in the material. The value will be overridden until tilemap.reset_constant is called. Which tile map to set a constant for is identified by the URL.

Parameters

url

string | hash | url the tile map that should have a constant set

constant

string | hash name of the constant

value

vector4 value of the constant

url

string | hash | url the tile map that should have a constant set

constant

string | hash name of the constant

value

vector4 value of the constant

Examples

The following examples assumes that the tile map has id "tile map" and that the default-material in builtins is used, which defines the constant "tint". If you assign a custom material to the tile map, you can set the constants defined there in the same manner.

How to tint a tile map to red:

function init(self)
    tilemap.set_constant("#tilemap", "tint", vmath.vector4(1, 0, 0, 1))
end

tilemap.set_tile

tilemap.set_tile(url, layer, x, y, tile, [h-flipped], [v-flipped])

Replace a tile in a tile map with a new tile. The coordinates of the tiles are indexed so that the "first" tile just above and to the right of origo has coordinates 1,1. Tiles to the left of and below origo are indexed 0, -1, -2 and so forth.

+-------+-------+------+------+
|  0,3  |  1,3  | 2,3  | 3,3  |
+-------+-------+------+------+
|  0,2  |  1,2  | 2,2  | 3,2  |
+-------+-------+------+------+
|  0,1  |  1,1  | 2,1  | 3,1  |
+-------O-------+------+------+
|  0,0  |  1,0  | 2,0  | 3,0  |
+-------+-------+------+------+

The coordinates must be within the bounds of the tile map as it were created. That is, it is not possible to extend the size of a tile map by setting tiles outside the edges. To clear a tile, set the tile to number 0. Which tile map and layer to manipulate is identified by the URL and the layer name parameters.

Parameters

url

string | hash | url the tile map

layer

string | hash name of the layer for the tile

x

number x-coordinate of the tile

y

number y-coordinate of the tile

tile

number index of new tile to set

[h-flipped]

boolean optional if the tile should be horizontally flipped

[v-flipped]

boolean optional i the tile should be vertically flipped

url

string | hash | url the tile map

layer

string | hash name of the layer for the tile

x

number x-coordinate of the tile

y

number y-coordinate of the tile

tile

number index of new tile to set

[h-flipped]

boolean optional if the tile should be horizontally flipped

[v-flipped]

boolean optional i the tile should be vertically flipped

Examples

-- Clear the tile under the player.
tilemap.set_tile("/level#tilemap", "foreground", self.player_x, self.player_y, 0)